2017-06-06 52 views
0

我想從我的Jenkinsfile中的兩個不同的回購拉特定標籤。標籤是通過從相關管道獲取最新的成功構建並使用這些值確定要簽出哪個標記來確定的。然而,由於SCM沒有替換我添加的withEnv變量,所以我遇到了問題。在下面的代碼,你可以看到我呼應了應該是什麼標籤(這回聲正常工作),但是當涉及到SCM檢查出的標籤LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD和LAST_SUCCESSFUL_SHARED_REPO_BUILD變量都沒有與他們的價值觀取代拉詹金斯管道中的特定標籤SCM

node { 

    stage('Checkout') { 
     withEnv([ 
      "LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD=${ sh (script: "curl <JENKINS_URL>/job/extensionsrepo/job/${BRANCH_NAME}/lastSuccessfulBuild/buildNumber", returnStdout: true) }", 
      "LAST_SUCCESSFUL_SHARED_REPO_BUILD=${ sh (script: "curl <JENKINS_URL>/job/sharedrepo/job/${BRANCH_NAME}/lastSuccessfulBuild/buildNumber", returnStdout: true) }" 
     ]) { 
      sh 'echo ${BRANCH_NAME}_${LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD}' 
      sh 'echo ${BRANCH_NAME}_${LAST_SUCCESSFUL_SHARED_REPO_BUILD}' 
      checkout scm 
      checkout([ 
       $class: 'GitSCM', 
       branches: [[name: 'refs/tags/${BRANCH_NAME}_${LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD}']], 
       doGenerateSubmoduleConfigurations: false, 
       extensions: [[ 
        $class: 'RelativeTargetDirectory', 
        relativeTargetDir: 'app/extensions' 
       ]], 
       submoduleCfg: [], 
       userRemoteConfigs: [[ 
        credentialsId: 'ssh-key', 
        url: '<GIT_URL>' 
       ]] 
      ]) 
      checkout([ 
       $class: 'GitSCM', 
       branches: [[name: 'refs/tags/${BRANCH_NAME}_${LAST_SUCCESSFUL_SHARED_REPO_BUILD}']], 
       doGenerateSubmoduleConfigurations: false, 
       extensions: [[ 
        $class: 'RelativeTargetDirectory', 
        relativeTargetDir: 'app/shared' 
       ]], 
       submoduleCfg: [], 
       userRemoteConfigs: [[ 
        credentialsId: 'ssh-key', 
        url: '<GIT_URL>' 
       ]] 
      ]) 
     } 
    } 

    // test, stage, deploy 
} 

任何關於我在這裏做錯了什麼指針將不勝感激。毫無疑問,我沒有做到正確,這是愚蠢的。

感謝

回答

0

嘗試更換單引號您結帳電話,你必須用雙引號分支變種。一般來說,在Groovy中,當包含嵌入變量時,您應該使用雙引號(參見What's the difference of strings within single or double quotes in groovy?)。

像:

checkout([ 
      $class: 'GitSCM', 
      branches: [[name: "refs/tags/${BRANCH_NAME}_${LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD}"]], 
      doGenerateSubmoduleConfigurations: false, 
      extensions: [[ 
       $class: 'RelativeTargetDirectory', 
       relativeTargetDir: 'app/extensions' 
      ]], 
      submoduleCfg: [], 
      userRemoteConfigs: [[ 
       credentialsId: 'ssh-key', 
       url: '<GIT_URL>' 
      ]] 
     ])