Aman
Aman

Reputation: 367

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.

Upvotes: 0

Views: 1684

Answers (1)

Siddhant Mishra
Siddhant Mishra

Reputation: 508

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

branch = "${env.BRANCH_SPECIFIER}"

Try using this .

Upvotes: 1

Related Questions