[英]How can I get the output of a command into an environmental variable in a Jenkinsfile?
So, I can capture a variable in a step like this: 因此,我可以按照以下步骤捕获变量:
stage('blah') {
script {
INVENTORY_FILE = sh(returnStdout: true, script: 'echo $(date +%Y%m%d).yml')
}
}
And this works. 这可行。 Except I need this variable to be in scope for the entire Jenkinsfile, for all stages, not just this one.
除了我需要这个变量在整个Jenkinsfile的作用域内,在所有阶段,而不仅仅是这个阶段。 But I can't seem to use sh() outside of a stage.
但是我似乎无法在舞台之外使用sh()。 Any ideas?
有任何想法吗?
You can define a variable at the top of Jenkinsfile, then you can access this variable in entire Jenkinsfile. 您可以在Jenkinsfile的顶部定义一个变量,然后可以在整个Jenkinsfile中访问此变量。
def INVENTORY_FILE
pipeline {
stages {
stage('blah') {
script {
INVENTORY_FILE = sh(returnStdout: true, script: 'echo $(date +%Y%m%d).yml').trim()
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.