Quantcast
Viewing latest article 1
Browse Latest Browse All 3

Answer by modle13 for How to define variable in Jenkins declarative pipeline?

You can also use environment block to inject an environment variable.

(Side note: sh is not needed for echo)

pipeline {    agent none    environment {        FOO = "bar"    }    stages {        stage("first") {            steps {                echo "${env.FOO}"                // or echo "${FOO}"            }        }    }}

You can even define the env var inside the stage block to limit the scope:

pipeline {    agent none    stages {        stage("first") {            environment {                FOO = "bar"            }            steps {                // prints "bar"                echo "${env.FOO}"                // or echo "${FOO}"            }        }        stage("second") {            steps {                // prints "null"                echo "${env.FOO}"                // or echo "${FOO}", pipeline would fail here            }        }    }}

Viewing latest article 1
Browse Latest Browse All 3

Trending Articles