jenkinsfile变量传递
2023-11-29 本文已影响0人
87d6dc4b11a7
pipeline {
agent any
environment {
ZIP_NODE = "xyz.zip"
}
stages {
stage ('test1') {
steps {
script {
ZIP_NODE = "abc.zip"
}
}
}
stage ('test2') {
steps {
script {
ZIP_NODE = "def.zip"
}
}
}
stage ('test3') {
steps {
script{
//打印结果def.zip,在script 内、sh外,双引号,打印的是被赋值后的全局变量
sh "echo ${ZIP_NODE}"
sh """
echo ${ZIP_NODE} #打印结果def.zip,在script内sh 内,3双引号,打印的是被赋值后的全局变量
"""
sh '''
echo ${ZIP_NODE} #打印结果xyz.zip, 3单引号打印出来的是environment中设置的变量值
'''
}
}
}
}
}
假如在sh
里面赋值就会报错,如下:
pipeline {
agent any
environment {
ZIP_NODE = "xyz.zip"
}
stages {
stage ('test1') {
steps {
script {
sh '''
ZIP_NODE = "abc.zip"
'''
}
}
}
stage ('test2') {
steps {
script{
//打印结果abc.zip,在script 内,sh外,双引号,打印的是被赋值后的全局变量
echo "${ZIP_NODE}"
sh """
echo ${ZIP_NODE} #打印结果abc.zip,在script内sh 内,3双引号,打印的是被赋值后的全局变量
"""
sh '''
echo ${ZIP_NODE} #打印结果xyz.zip, 3单引号打印出来的是environment中设置的变量值
'''
}
}
}
}
}