Jenkinsfile variable used in two separate stages
In a declarative pipeline, @mkobit's answer won't work. You can, however, switchinto script mode explicitly and use its scoping, e.g. like so:
...
steps {
script {
def foo = sh script: "computeFoo", returnStdout: true
node('name') {
script {
someStep()
}
}
}
}
...
Just define the variable before your node
block:
def rev = ''
node('build') {
stage('Checkout') {
checkout scm
}
stage('Build') {
bat(script: 'build')
rev = readFile('result')
}
}