【问题标题】:Setting build properties in Android Gradle via Jenkins通过 Jenkins 在 Android Gradle 中设置构建属性
【发布时间】:2016-09-18 09:37:27
【问题描述】:

你如何告诉 Jenkins 在 Android 项目的 gradle.properties 中设置一个属性?我已经想出了如何将属性从 Gradle 获取到 Jenkins(通过使用 EnvInject 插件 并简单地在属性文件字段中输入gradle.properties),但我还想要由管理的内部版本号Jenkins 将被注入到构建工件中。

我还想设置生成的工件的文件名,我认为需要使用archivesBaseName 注入该文件名。但是该属性不是gradle.properties 的一部分,所以我想知道如何访问它?

到目前为止,我只找到了在 Android 项目本身中更改 build.gradle 文件(或其他 gradle 脚本)的解决方案。但这不是我想做的,因为这会使 Android 代码库依赖于 Jenkins。

相反,我希望 Jenkins 在编译代码之前向 Android 项目提供内部版本号和工件文件名。

服务器在 Mac 上运行。有人对此有解决方案吗?任何可以完成这项工作的 shell/Groovy 脚本都会受到欢迎。

【问题讨论】:

    标签: java android jenkins gradle continuous-integration


    【解决方案1】:

    我们只是在编写一个文件 version.properties,它是由 jenkins "echo "VERSION_CODE=${BUILD_NUBMER}" > version.properies" 脚本生成的。

    然后 gradle 脚本将其导入如下:

    // Version code is loaded from a properties file
            def versionPropsFile = file('version.properties')
            if (versionPropsFile.canRead()) {
                def Properties versionProps = new Properties()
                versionProps.load(new FileInputStream(versionPropsFile))
    
                def code = versionProps['VERSION_CODE'].toInteger()
    
                versionCode code
            }
            else {
                throw new GradleException("Could not read version.properties!")
            }
    
            buildConfigField "String", " some _VERSION", "\"${getVersionString()}\""
        }
    

    【讨论】:

      猜你喜欢
      • 2014-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      相关资源
      最近更新 更多