Reputation: 3114
I want to set some jenkins environment variables in run time based on my computation. How can i set this run-time in my jenkinsfile's step
section.
for example: based on my calculation i get abc=1
. How can i set this in real time in my jenkinsfile's step
section so that i can use it later by calling $abc
.
I am declaring my pipeline and environment variables as explained here: https://jenkins.io/doc/pipeline/tour/environment/
i'm using Jenkins ver. 2.41
Upvotes: 1
Views: 2459
Reputation: 2792
Here an example how to set variables and use it in the same Jenkinsfile.
The Variable versionToDeploy will be used by the build job
step.
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'build the artifacts'
script {
versionToDeploy = '2.3.0'
}
}
}
}
post {
success {
echo 'start deploy job'
build job: 'pipeline-declarative-multi-job-deploy', parameters: [[$class: 'StringParameterValue', name: 'version', value: versionToDeploy]]
}
}
}
Upvotes: 1