Reputation: 161
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. But I can't seem to use sh() outside of a stage. Any ideas?
Upvotes: 0
Views: 87
Reputation: 13712
You can define a variable at the top of Jenkinsfile, then you can access this variable in entire Jenkinsfile.
def INVENTORY_FILE
pipeline {
stages {
stage('blah') {
script {
INVENTORY_FILE = sh(returnStdout: true, script: 'echo $(date +%Y%m%d).yml').trim()
}
}
}
}
Upvotes: 2