Jenkins pipeline pass all parameters down to downstream jobs

后端 未结 3 1132
情深已故
情深已故 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:16

    The following seems to work (I haven't tested it extensively though):

    pipeline {
        agent any
        parameters {
            string(name: 'PARAM1', description: 'Param 1?')
            string(name: 'PARAM2', description: 'Param 2?')
        }
        stages {
            stage('Example') {
                steps {
                    echo "${params}"
                    script {
                        def myparams = currentBuild.rawBuild.getAction(ParametersAction).getParameters()
                        build job: 'downstream-pipeline-with-params', parameters: myparams
                    }    
                }
            }
        }
    }
    

    Drawback: to access rawBuild and getAction you have to disable the Groove sandbox or approve these signatures in Jenkins under Manage Jenkins > In-process Script Approval. This dialog will show you that you might introduced a security vulnerability. So it depends on your environment if you want to take this risk or not.

提交回复
热议问题