Jenkins变量
Jenkins服务器查看
以下网址提供了全局变量页,可参考使用
https://opensource.triology.de/jenkins/pipeline-syntax/globals
脚本中打印所有变量
sh "env"
会将当前env中所有的变量全打印出来。
stages {
stage("stage 1: Test dingding notify") {
steps {
echo 'Test dingding notify'
sh "env"
}
}
}
后台添加全局变量
打开全局变量配置。【系统管理】->【系统配置】找到全局配置,点添加即可。
流水线中添加变量
该流水线实例作用域的参数放在最外层(跟全局agent同级)。这里定义的变量全局都可以引用。
pipeline {
agent any
parameters {
string(name: 'testTag', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
}
stages {
stage("xx") {
steps {
sh 'echo ${testTag}. Pleace select project'
}
}
}
}
任何时候利用脚本块给全局变量“env”赋值,该流水线声明周期内也是可以访问到的。
steps {
script {
env.PERSON = "Mr Jenkins"
}
sh 'env'
}
input定义参数
stage("stage 2: deploy") {
input {
message "Should we continue?"
ok "Yes, we should."
parameters {
choice(name: 'PERSON', choices: ['Jenkins', 'Pipeline'], description: 'Who should I say hello to?')
}
}
steps {
script {
env.PERSON = "${PERSON}"
}
sh 'env'
}
}