从 Android Gradle 访问 Azure DevOps 变量
Access Azure DevOps variables from Android Gradle
在我的 gradle 脚本中构建我的 Android 应用程序时 DevOps Pipeline, I want to access the predefined Azure DevOps variables,它看起来像这样:
apply plugin: 'com.android.application'
// When running on the CI, this will return the build-number. Otherwise use 1
def buildNumber = System.getenv("Build.BuildNumber") as Integer ?: 1
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "my.app.id"
minSdkVersion 23
targetSdkVersion 29
versionCode buildNumber
versionName "1.0." + buildNumber
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
...
}
在 Azure DevOps 管道中的 Bitrise, the call def buildNumber = System.getenv("BITRISE_BUILD_NUMBER") as Integer ?: 1
worked just fine, but I have no idea, how to access the Build.BuildNumber 变量上。
好的,我知道如何访问变量了。诀窍是用下划线替换点,用大写字母替换小写字母。
所以
def buildNumber = System.getenv("Build.BuildNumber") as Integer ?: 1
变成
def buildNumber = System.getenv("BUILD_BUILDNUMBER") as Integer ?: 1
鉴于 Build.BuildNumber 看起来像 20191129.16,这是一个无效的版本代码,我切换到
def buildNumber = System.getenv("BUILD_BUILDID") as Integer ?: 1
在我的 gradle 脚本中构建我的 Android 应用程序时 DevOps Pipeline, I want to access the predefined Azure DevOps variables,它看起来像这样:
apply plugin: 'com.android.application'
// When running on the CI, this will return the build-number. Otherwise use 1
def buildNumber = System.getenv("Build.BuildNumber") as Integer ?: 1
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "my.app.id"
minSdkVersion 23
targetSdkVersion 29
versionCode buildNumber
versionName "1.0." + buildNumber
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
...
}
在 Azure DevOps 管道中的 Bitrise, the call def buildNumber = System.getenv("BITRISE_BUILD_NUMBER") as Integer ?: 1
worked just fine, but I have no idea, how to access the Build.BuildNumber 变量上。
好的,我知道如何访问变量了。诀窍是用下划线替换点,用大写字母替换小写字母。
所以
def buildNumber = System.getenv("Build.BuildNumber") as Integer ?: 1
变成
def buildNumber = System.getenv("BUILD_BUILDNUMBER") as Integer ?: 1
鉴于 Build.BuildNumber 看起来像 20191129.16,这是一个无效的版本代码,我切换到
def buildNumber = System.getenv("BUILD_BUILDID") as Integer ?: 1