How can you pass same parameters to different builds without redundant code in Jenkins Pipeline

牧云@^-^@ 提交于 2019-12-12 04:32:26

问题


How can you pass same parameters to different builds without redundant code in Jenkins Pipeline groovy. I don't want to repeat the parameters.

node('master') {
    parallel(
        "stream 1(X)" : {
        stage('X') {
            build 'Job1', parameters: [string(name: 'branch', value: 'trunk'), string(name: 'freq', value: 'Continuous')]
        }
        },
        "stream 2 (Y)" : {
            stage('Y') {
                build 'Job2', parameters: [string(name: 'branch', value: 'trunk'), string(name: 'freq', value: 'Continuous')]
            }
        }
    )
}

回答1:


It is pretty easy : just add a function, say buildJob, that will take your job name as a parameter and then set all jobs parameters as you do it now :

node('master') {
    parallel(
        "stream 1(X)" : {
        stage('X') {
            buildJob("Job1")
        }
        },
        "stream 2 (Y)" : {
            stage('Y') {
                buildJob("Job2")
            }
        }
    )
}

def buildJob(jobName) {
    build name: jobName, parameters: [string(name: 'branch', value: 'trunk'), string(name: 'freq', value: 'Continuous')]
}


来源:https://stackoverflow.com/questions/40509430/how-can-you-pass-same-parameters-to-different-builds-without-redundant-code-in-j

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