I have a pipeline my team is using to spin up cloud VM's and deploy a software stack to them. Part of this process is to bundle up the artifacts from the builds they select. Right now im just grabbing last success of the jobs listed but ive encountered issues of that job being built again in another process before the pipeline can create its bundle, making the bundle grab an artifact built with the wrong dependencies.
def DeployModule(jobName, jobBranch, serverHostName, database){
build job: jobName, parameters: [[$class: 'StringParameterValue', name: 'Branch', value: jobBranch], [$class: 'StringParameterValue', name: 'DatabaseAction', value: database], [$class: 'StringParameterValue', name: 'Profile', value: serverHostName]]
println "$jobName Succesfull"
}
Is there any way to alter my simple build job method to pull out the actual build number that was triggered? The pipeline console prints what build number is created im just not sure how to get it in my groovy code.
[Pipeline] build (Building tms-auto-build)
Scheduling project: tms-auto-build
Starting building: tms-auto-build #298
BUILD_NUMBER is the current build number. You can use it in the command you execute for the job, or just use it in the script your job executes. See the Jenkins documentation for the full list of available environment variables.
Go to Script Console under Manage Jenkins, this script will print the name of all jobs including jobs inside of a folder and the folders themselves: Jenkins. instance. getAllItems(AbstractItem.
This was actually kind of a no brainer. if I just set build job: jobName
to a variable, that variable is a RunWrapper
https://github.com/jenkinsci/pipeline-plugin/blob/d3f66c6f04d1d979957f02819b19291e2c35e276/support/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java
RunWrapper as a .getNumber() that works perfect
def testing = build job: "tms-auto-build"
println testing.getNumber()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With