How to use jenkins to declare BUILD_NUMBER environ

2019-09-10 04:55发布

问题:

    InterfaceVersion = Interface-Version
    Interface-Version = V2  
         //     property environment = env
     label = ${env.BUILD_NUMBER} 
     ReleaseVersion = Release-Version
     Release-Version = ${env.release_version} 

This is what I have in my gradle.properties file. I know I am doing it wrong. How can I make it display a build_number and release_version??

回答1:

The values in gradle.properties files are not interpolated by default. For this you would need to use some Gradle plugin that does it, or you have to do it manually. The default Gradle behaviour just parses them as plain old properties files. If you know which ones should have the dynamic values, just set them in your build.gradle file instead of in gradle.properties, the effect will be the same. If you need the dynamicness of being able to use it in the gradle.properties files, either use a plugin that does such interpolations or manually evaluate each value as a Groovy expression so that the placeholders get replaced.

You can search through the list of available plugins on the Gradle Plugins Portal. E. g. com.admc.javaPropFile is a candidate you might want to have a look at.



回答2:

Here it is:

defaultConfig {
        applicationId "com.project"
        minSdkVersion 16
        versionCode 22
        versionName "1.0.0.13"
    }

And to read the atribute:

String versionName = BuildConfig.VERSION_NAME;


标签: gradle