build.gradle文件配置
def gitVersionCode() {
def cmd = 'git rev-list HEAD --first-parent --count'
cmd.execute().text.trim().toInteger()
}
def gitVersionTag() {
def cmd = 'git describe --tags'
def version = cmd.execute().text.trim()
def pattern = "-(\\d+)-g"
def matcher = version =~ pattern
if (matcher) {
version = version.substring(0, matcher.start()) + "." + matcher[0][1]
} else {
version = version + ".0"
}
return version
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.race604.example"
minSdkVersion 15
targetSdkVersion 23
versionCode gitVersionCode()
versionName gitVersionTag()
}
......
参考地址:
玩转Jenkins - Android发布自动版本号 https://www.jianshu.com/p/324ce75bea5f
转载于:https://blog.51cto.com/4789781/2117490