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

Bram Gerritsen picture Bram Gerritsen · May 4, 2016 · Viewed 104.8k times · Source

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.

Answer

abguy picture abguy · Mar 24, 2017

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