0
的build.gradleAPK版本名称 - 詹金斯
compileSdkVersion 23
buildToolsVersion "25.0.2"
applicationVariants.all { variant ->
def flavor = variant.mergedFlavor
if (variant.buildType.isDebuggable()) {
flavor.versionName = "Beta Revision: ${svnRevisionDebug()}";
flavor.versionCode = 1;
} else {
if (project.hasProperty('projVersion')) {
println "Assemble release with parameter " + project.projVersion;
flavor.versionName = ""+ project.projVersion;
} else {
flavor.versionName = '10.0.0'
}
flavor.versionCode = 1;
}
}
在詹金斯执行shell
./gradlew assembleRelease -PprojVersion=123
詹金斯输出控制台
+ ./gradlew assembleRelease -PprojVersion=123
Incremental java compilation is an incubating feature.
Unix runtime
Assemble release with parameter 123
输出
Unix runtime
从svnRevisionDebug()
def svnRevisionDebug() {
if (System.properties['os.name'].toLowerCase().contains('windows')) {
println "Windows runtime"
new ByteArrayOutputStream().withStream { os ->
def result = exec {
executable = 'svn'
args = ['info', '-r', 'HEAD']
standardOutput = os
}
def outputAsString = os.toString()
def matchLastChangedRev = outputAsString =~ /Last Changed Rev:(\d+)/
ext.svnRev = "${matchLastChangedRev[0][1]}".toInteger()
}
return svnRev
} else {
println "Unix runtime"
def p = ['/bin/bash', '-c', /svn info -r HEAD | grep '^Revision:' | sed -e 's\/^Revision: \/\/'/].execute()
p.waitFor()
return p.text.trim()
}
}
来了,但,当我从清单反编译的apk我看到
android:versionName="1.0"
跆拳道? 可能是与创建apk文件时多次调用的applicationVariants.all一起使用的方法(您可以看到jenkins日志“Unix runtime”和“Assemble release with parameter”
哪种方法可以在versionName中注入参数?