-
Bug
-
Resolution: Incomplete
-
Critical
-
None
-
Jenkins v2.164.3
Extensible Choice Parameter plugin v1.6.0
I have 2 Jenkins jobs, Job1 and Job2, and Job1 triggers Job2 via this pipeline DSL
node('someNode') { stage('Call Job2') { build job: 'Job2', parameters: [ new StringParameterValue('ExtensibleChoiceParam', 'TARGET_VERSION') ], wait: false } }
Job2 has this Groovy script as its Extensible Choice Parameter for variable TARGET_VALUE, which provides a list of ALL successful builds for Job1
// code placeholder import hudson.model.* BUILD_JOB_NAME = "Job1" def getBuildJob() { def buildJob = null Hudson.instance.getAllItems(Job.class).each { if (it.fullName == BUILD_JOB_NAME) { buildJob = it } } return buildJob } List<String> getAllBuildNumbers(Job job) { List<String> buildNumbers = [] (job.getBuilds()).each { def status = it.getBuildStatusSummary().message if (status.contains("stable") || status.contains("normal")) { buildNumbers.add(it.displayName) } } return buildNumbers } Job buildJob = getBuildJob() List<String> buildNumbers = null if (buildJob) { buildNumbers = getAllBuildNumbers(buildJob) } return buildNumbers
Job2 does nothing but prints TARGET_VERSION, so it just does this
node('someNode') { stage('Print TARGET_VERSION') { println "TARGET_VERSION: $TARGET_VERSION" } }
If Job1 has the following build history for example,
Build# Status $4 Success #3 Fail #2 Success #1 Fail
If I click on Job2's Build with parameters link, I get the correct list, that is, as shown below, so I know the script is correct.
#4 #2
When Job1 triggers Job2 (per Job1's pipeline DSL above), I expect Job2 to print #4, Job1's latest successful build. However, it prints out #2, the previous successful build. Why?