在 Jenkins 中,我尝试设置一个具有空值的环境变量,并且我将分阶段更新该变量的值。但shell脚本未能获取最新值,旧值为echo。
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 正在脚本下工作{}。但它在 sh {} 下不起作用。