简体   繁体   中英

Jenkins pipeline - issue with Branch parameter

I am trying to write a master Jenkinsfile which will call all the build jobs. In respective jobs, I have used {BRANCH_SPECIFIER} using gitparameter and few i have not. The master code

if ((params.ENVIRONMENT == 'dev' || params.ENVIRONMENT == 'int' && (params.ServiceName == 'Name' || params.ServiceName == 'ALL'))
                stage('stage1') {
                    b = build(job: 'jobname', parameters: [[$class: 'GitParameterValue', name: 'branch', value: branch]], propagate: false).result
                    if(b=='FAILURE'){
                            echo " job failed"
                            currentBuild.result = 'UNSTABLE'
                        }

Child build job

branch = "${params.BRANCH_SPECIFIER}"
    WORKING_BRANCH = "${params.BRANCH_SPECIFIER}"
    echo "Branch Specifier is ${branch}"
  stage('Checkout'){
    checkout([$class: 'GitSCM', branches: [[name: "${branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '', url: 'repo.git']]])
    }

It is not able to resolve {BRANCH_SPECIFIER} in the individual jobs Any doc/info will be helpful.

You should use it as normal environment variables . Jenkins passes those parameters as environment variables .

branch = "${env.BRANCH_SPECIFIER}"

Try using this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM