Jenkins pipeline pass all parameters down to downstream jobs

后端 未结 3 1121
情深已故
情深已故 2021-02-19 11:56

I have a pipeline job named buildall which looks like this:

pipeline {
    stages {
        stage(\"job1\") {
            build job: \"job1\"
           


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-19 12:14

    If you don't care about the parameter types, this approach does not require disabling the Groovy Sandbox - it simply assumes that all parameters can be treated as a string (won't work for "File", for example):

    def myparams = params.collect{
        string(name: it.key, value: it.value)
    }
    build job: 'downstream-job', parameters: myparams
    

    It wouldn't be too hard to expand the logic to handle predefined non-string parameter types, but I agree that this should not be necessary. A better approach would be to expose parameters in the format required by the build() DSL closure, including type specifics that are currently not visible via the "params" global variable, or perhaps to add a boolean, eg:

    // I wish:
    build job: 'downstream-job', includeMyParameters: true, parameters: anyExtras
    

提交回复
热议问题