Jenkinsで環境変数に空の値を設定してみましたが、段階的に変数の値を更新していきます。しかし、シェルスクリプトは最新の値を取得できず、古い値はエコーです。
pipeline {
agent {
label 'test'
}
tools {
jdk 'Java 1.8'
}
environment {
DASHBOARD_PATH = '/pkg/vddfg/oradfg/apache/htdocs/'
COMMIT_ID = ' '
GROUP_ID = 'Dashboard3'
ARTIFACT_ID = 'MS_CSD_DB3'
MS_VERSION = ' '
JAVA_HOME = tool('Java 1.8')
PATH="${JAVA_HOME}/bin:${env.PATH}"
}
stages {
stage('SCM CheckOut'){
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], gitTool: 'default (git from PATH)', submoduleCfg: [], userRemoteConfigs: [[credentialsId: '9754f1e7-7095-4f68-bf56-6e92a292a241', url: 'git@demucvtr13:csd/csd-dashboard3.git']]])
//def gitCommit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
//sh 'echo ${gitCommit}'
script {
COMMIT_ID = withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin:/pkg/vddfg/home/oradfg/csw/bin']){ sh(script: "git rev-parse HEAD", returnStdout: true).trim() }
echo COMMIT_ID
}
}
}
stage('Artifact Upload') {
steps {
script {
def now = new Date()
MS_VERSION = now.format("yyMMdd_HHmm", TimeZone.getTimeZone('GMT+1'))
echo "${COMMIT_ID}"
echo "${GROUP_ID}"
echo "${ARTIFACT_ID}"
echo "${MS_VERSION}"
withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']) {
sh '''
commit_id="${COMMIT_ID}"
grp_id="${GROUP_ID}"
art_id="${ARTIFACT_ID}"
ver_id="${MS_VERSION}"
'''
}
}
}
}
}
}
Echo は script{} の下で動作しています。しかし、sh {} の下では動作しません。