Unable to pass build number into Gradle?
I cannot seem to get the TeamCity build number passed into my Gradle build. I couldn't see build.number appearing anywhere, so I tried defining a build property that gets assigned the value %system.build.number% and I can't see that either.
I tried this in my Gradle build and was unable to see anything related to the build number in all the emitted properties:
System.getProperties().each { System.println(it) }
Any tricks to accessing the build number in Gradle?
Please sign in to leave a comment.
Alan,
You can refer to buildnumber in gradle build like this:
Also, you may want to take a look at other properties available inside build script:
How would that interoperate with an interactive Gradle invocation at the command line? I get an error about the 'teamcity' property not being defined.
I need to support both.
As you can not access TeamCity from interactive mode, you will need some default value.
Take a look at the following example:
I tried this, but it doesn't work:
distTar {
baseName = project.name+'.'+
project.version+'.'+
System.getProperty("system.rnf.brach_name")
if (hasProperty("teamcity")) {
baseName = baseName +'.'+
teamcity['build.number']+'.'+
teamcity['build.vcs.number.1']
}
archiveName = baseName+'.tar'
into(baseName) {
from '.'
include 'config/*'
include 'run-script/*.sh'
}
}
this works when I don't have teamcity (on my local machine), but even when it runs in teamcity, it doesn't add the build.number.
When I have:
distTar {
baseName = project.name+'.'+
project.version+'.'+
System.getProperty("system.rnf.brach_name")+'.'+
teamcity['build.number']+'.'+
teamcity['build.vcs.number.1']
archiveName = baseName+'.tar'
into(baseName) {
from '.'
include 'config/*'
include 'run-script/*.sh'
}
}
then it works in teamcity, but not on the local machine.
Gavriel,
Would you mind attaching a build log from TeamCity server for variant that works locally and does not work in teamcity?
The build log when it doesn't work looks like this:
Thank you for the log.
Groovy applies hasProperty("teamcity") call to Task instance. Please, specify Project instance explicitly like this:
if (project.hasProperty("teamcity")) {
...
}
it should fix the issue