问题
I posted How to pass Extensible Choice parameter type to Jenkins pipeline? and found an answer, that is, I least I don't get the core dump anymore. However, I have 2 follow up questions.
Again I have 2 jobs, Job1 and Job2. Job1 just triggers Job2. Job2 has an extensible choice parameter called TARGET_VERSION
which runs a script that shows Job1's successful build numbers. Here's the Groovy script
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
And Job2 is does nothing except this
node('someNode') {
stage('Print target version') {
println "$TARGET_VERSION"
}
}
So if Job1 has the following build history
Build# result
--------------------
#4 success
#3 fail
#2 success
#1 fail
When I run Job2's Build with parameters
, I get a TARGET_VERSION
dropdown list showing
#4
#2
which are Job1's build numbers that passed.
However, Job1 is a pipeline job, and I trigger Job2 this way
build job: 'Job2',
parameters: [
new StringParameterValue('ExtensibleChoiceParam',
'TARGET_VERSION',
'666')
],
wait: false
IOW, I want to force a value for Job2's TARGET_VERSION
, 666
in this case (LOL). I have 2 issues.
Issue#1: Job2 does NOT print out 666
Issue#2: Job2 prints out #2
instead of #4
. IOW, it prints out the previous successful build, NOT the latest one.
Question #1. How can I pass-in a value from Job1 to Job2 extensible choice parameter?
Question #2: Why is Job#2 printing out the Job1's previous successful build, instead of the latest one?
来源:https://stackoverflow.com/questions/60442259/how-to-pass-extensible-choice-parameter-value-to-jenkins-pipeline