Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 877
Bram Gerritsen Avatar asked May 04 '16 10:05

Bram Gerritsen


People also ask

How do you use a Boolean parameter in Jenkins pipeline?

Step 1: Click on Configure. Step 2: Then look for “This project is parameterized” checkbox. Then check the checkbox. A small section will open up for you to enter the details in.

How does Jenkins pass parameters to a job?

Using build parameters, we can pass any data we want: git branch name, secret credentials, hostnames and ports, and so on. Any Jenkins job or pipeline can be parameterized. All we need to do is check the box on the General settings tab, “This project is parameterized”: Then we click the Add Parameter button.

How are parameters used in pipeline scripts?

You just have to use params. [NAME] in places where you need to substitute the parameter. Here is an example of a stage that will be executed based on the condition that we get from the choice parameter. The parameter name is ENVIRONMENT , and we access it in the stage as params.


2 Answers

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))     ] 
like image 105
abguy Avatar answered Sep 26 '22 08:09

abguy


Assuming

value: update_composer 

was the issue, try

value: Boolean.valueOf(update_composer) 

is there a less cumbersome way in which I can just pass ALL the pipeline parameters to the downstream job

Not that I know of, at least not without using Jenkins API calls and disabling the Groovy sandbox.

like image 36
Jesse Glick Avatar answered Sep 22 '22 08:09

Jesse Glick