Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

jenkins - How to pass boolean parameter value in pipeline to downstream jobs?

I'm using Jenkins v2.1 with the integrated delivery pipeline feature (https://jenkins.io/solutions/pipeline/) to orchestrate two existing builds (build and deploy).

In my parameterized build I have 3 user parameters setup, which also needs to be selectable in the pipeline.

The pipeline script is as follows:

node: {
    stage 'build'
    build job: 'build', parameters: [[$class: 'StringParameterValue', name: 'target', value: target], [$class: 'ListSubversionTagsParameterValue', name: 'release', tag: release], [$class: 'BooleanParameterValue', name: 'update_composer', value: update_composer]]

    stage 'deploy'
    build job: 'deploy', parameters: [[$class: 'StringParameterValue', name: 'target', value: target]]
}

This works correctly except for the BooleanParameterValue. When I build the pipeline the following error is thrown:

java.lang.ClassCastException: hudson.model.BooleanParameterValue.value expects boolean but received class java.lang.String

How can I resolve this typecasting error? Or even better, is there a less cumbersome way in which I can just pass ALL the pipeline parameters to the downstream job.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In addition to Jesse Glick answer, if you want to pass string parameter then use:

build job: 'your-job-name', 
    parameters: [
        string(name: 'passed_build_number_param', value: String.valueOf(BUILD_NUMBER)),
        string(name: 'complex_param', value: 'prefix-' + String.valueOf(BUILD_NUMBER))
    ]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...