How do you pass build metadata (version, commit) reliably between Jenkins stages?
BeginnerProductionJenkins in Production
Answer
Compute once in an early stage and store in env.VAR (visible across stages and agents), or write a small build.properties file and stash it. Avoid Groovy global variables for values needed after an agent change, and avoid recomputing the version in each stage, which can produce different values.
script { env.APP_VERSION = "1.4.${env.BUILD_NUMBER}-${env.GIT_COMMIT.take(7)}" }
More on Jenkins in Production
How do you run Jenkins for high availability and scale?AdvancedHow do you tune the Jenkins controller JVM and avoid out-of-memory crashes?AdvancedHow do you back up and restore Jenkins?IntermediateHow do you upgrade Jenkins and its plugins safely?IntermediateHow do you harden a Jenkins controller?AdvancedHow do you configure dynamic Kubernetes agents in Jenkins for production use?Intermediate