Accesing github environment variables in jenkinsfile pipeline

46 views
Skip to first unread message

Leonidas Kanellopoulos

unread,
Sep 27, 2017, 9:39:24 PM9/27/17
to Jenkins Users
I have a multi repo job and want to check out in one pipeline 2 branches ( 1 from each repo ) 

From repo A I Poll for a feature*  and then I want to attempt to build repo B with that same feature* or fallback to develop branch.

In the GUI job version I was using checkout to specific local branch with ** which populated the GIT_LOCAL_BRANCH env variable. and hence repo B had alternative strategy checkout with 
GIT_LOCAL_BRANCH or develop. 


Calling the env,GIT_LOCAL_BRANCH always returns null . 

I read online that this variable is only accessed/works for a multi-branch pipeline ?

Is there no other way to get the git branch that  was just checked out  from the first repo in order to pass it down ? 


Below is the jenkinsfile.

node {

  stage ('Stage CheckOut 1'){ 
   
//Repo A ( has Polling )    
 checkout([$class: 'GitSCM', branches: [[name: '*/feature**']], 
 doGenerateSubmoduleConfigurations: false, extensions: [[$class:
 'RelativeTargetDirectory', relativeTargetDir: 'android'], [$class:'LocalBranch', localBranch: '**']],
 submoduleCfg: [], userRemoteConfigs:
 [[credentialsId: '', url:

//Checking if similar branch name as repo A exists in repo B 
 def b  = resolveScm source: [$class: 'GitSCMSource', credentialsId: '',
 id: '_', remote: 'https://github.com/.....git', traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait']]],
 targets: [env. GIT_LOCAL_BRANCH, 'develop']
 checkout b
 
  }   
  }  
Reply all
Reply to author
Forward
0 new messages