Local variables in pipeline

Variables in a Jenkinsfile can be defined at the global level and stage level.

In the below pipeline, we have defined two variables "TRAINING"  and "TOPIC". The stage "local" will run without any issues as both the variables have value.

But stage "local" will have an issue, as the value of the "TOPIC" variable is not available in the stage.

pipeline {
    agent any
    environment {
        TRAINING = "jenkins"
    }
    stages{
        stage("local") {
            environment {
                TOPIC = "training"
            }
            steps {
                sh " echo training is ${TRAINING} and topic is ${TOPIC}"
            }
        }
        stage("global") {
            steps {
                sh "echo training is ${TRAINING} and topic is ${TOPIC}"
            }
        }
    }
}

Recent Comments

No comments

Leave a Comment