I know I can have an environment section on jenkins pipeline (declarative) for a stage. Like this:
stage('Name') {
environment {
NAME = value
}
steps {
script {
Do something using these env vars
}
}
}
I want to write a groovy function, to define some env vars, and run something, and call it from a few pipelines. Something like:
def function () {
environment {
NAME = value
}
sh "do something using these env vars"
}
Is it possible somehow?
(I know I can write sh "ENV=value; some CMD"
but I have few variables, and it is less read-able).