Adding another example and full implementation based on the answer above by @hctahkram !
pipeline {
agent any
stages {
stage("Trigger downstream job") {
steps {
script {
buildResult = build(job: "downstream-job", wait: true)
env.A = buildResult.buildVariables.A
}
sh("echo $A")
}
}
}
}
pipeline {
agent any
stages {
stage("Define A") {
steps {
script {
env.A = "aaa"
}
sh("echo $A")
}
}
}
}