How to implement BUILD_NUMBER in gradle?


#1

I am trying to declare a build_number and release-version in gradle using by rewriting a ant script to gradle.

	<property name="Interface-Version" value="V2" />
	<property environment="env"/>
	<property name="label" value="${env.BUILD_NUMBER}"/>
	<property name="Release-Version" value="${env.release_version}"/>

(Mark Vieira) #2

Use extra properties.

ext {
  releaseVersion = System.getenv('release_version')
}

#3

It prints out null. Am I suppose to hard code the version number somewhere in the env settings?


(Mark Vieira) #4

Where are these environment variables coming from? Are they set by your continuous integration server?

Ant is simply grabbing environment variables. What I showed is the Gradle equivalent. There is no such thing as a “build number” in either Ant or Gradle. I expect something (Jenkins, TeamCity, etc) is injecting them into the environment.


#5

It’s probably Jenkins I have 3 Jenkins file but none of them specify “Build_number”.


(Gil C) #6

It does look like those are Jenkins environment variables another way you could do it is something like this (if you’re using git)

def gitVersion() { if (!System.getenv('CI_BUILD')) { // don't care return 1 } def cmd = 'git rev-list HEAD --first-parent --count' cmd.execute().text.trim().toInteger() }