简体   繁体   中英

Jenkins groovy pipeline - retrieve build number of built job

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

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM