【问题标题】:Dynamically setting TeamCity version numbers based on Gradle file?根据 Gradle 文件动态设置 TeamCity 版本号?
【发布时间】:2021-03-08 22:30:15
【问题描述】:

我想使用存储我的版本和内部版本号的 android 项目中的 Gradle 文件更改 TeamCity Cloud 2020.2.2 中的内部版本号格式。

想要实现build号

VERSION_MAJOR+VERSION_MINOR+VERSION_PATCH+Teamcity_Buildcounter = 1.1.3.48

我想要 TeamCity 中的 Gradle 值,一旦 Teamcity Buildcounter 增加,更新 Gradle 文件中的值并提交?直到现在我都没有找到办法。任何想法我如何才能实现所有答案都非常古老,并非特定于 android

build.gradle

def VERSION_MAJOR=1
def VERSION_MINOR=1
def VERSION_PATCH=3

//Create a variable called keystorePropertiesFile, and initialize it to your
//keystore.properties file, in the rootProject folder.
def keystorePropertiesFile = rootProject.file("keystore.properties")

// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()

// Load your keystore.properties file into the keystoreProperties object.
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 30
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
    defaultConfig {
        applicationId "xxx"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode VERSION_BUILD
        versionName VERSION_MAJOR + "." + VERSION_MINOR + "." + VERSION_PATCH
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        archivesBaseName = "Appname-v$versionName"

// Rest code continues

我的设置:

【问题讨论】:

  • 不完全是您正在寻找的东西,但这个library 可能会有所帮助。
  • @YASAN 该库只是生成已经完成的版本号。我认为这与我的问题无关

标签: gradle teamcity


【解决方案1】:

由于内部版本号可以使用参数,你可以试试这个:

  • 将“内部版本号格式”更改为%VERSION_BY_GRADLE%.%build.counter%
  • VERSION_BY_GRADLE一个默认值,例如"1.0" 所以配置可以运行
  • 在您需要完整版本号之前,请在任何步骤通过sending service message 使用echo / Write-Host / print 命令将其更新为teamcity ##teamcity[setParameter name='VERSION_BY_GRADLE' value='put something from your code']
  • 随意尝试,尝试%VERSION_NUMBER% 而不是%VERSION_BY_GRADLE%.%build.counter% 并完全手动编写

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-05
    • 2016-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    • 2017-11-27
    相关资源
    最近更新 更多