Pipeline pass parameters to downstream jobs

匿名 (未验证) 提交于 2019-12-03 01:25:01

问题:

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.

回答1:

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.



回答2:

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


回答3:

like Jesse Jesse Glick and abguy said you can enumerate string into Boolean type:

Boolean.valueOf(string_variable) 

or the opposite Boolean into string:

String.valueOf(boolean_variable) 

in my case I had to to downstream Boolean parameter to another job. So for this you will need the use the class BooleanParameterValue :

build job: 'downstream_job_name', parameters: [ [$class: 'BooleanParameterValue', name: 'parameter_name', value: false], ], wait: true 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!