Stage‑level environment variables in Declarative Pipeline: Do they propagate to the post section?
0 reputation · 24 May 2024, 13:59 UTC
Unclear Propagation of Stage‑level Environment Variables
In a Declarative Pipeline, the environment directive can be placed at the pipeline, stage, or step level. Pipeline‑level variables are universally available, but the spec does not state whether a variable declared inside a stage’s environment block is also visible in that stage’s post block.
The goal is to determine if the post section inherits the stage‑level scope, which affects cleanup logic that relies on those variables. Current documentation is silent, and behavior may differ between Jenkins 2.400+ and older releases.
- Does a stage‑level environment variable appear in the
postblock? - Is the visibility consistent across Jenkins 2.400+ and earlier versions?
- What are the implications for scripts that run in
postwhen the variable is missing?