jenkinsci / jenkinsci/workflow-support-plugin

[JENKINS-59990] values set by environment directive are not captured for RunWrapper.getBuildVariables

Open
#418 1 comment 0 reactions 0 assignees View on GitHub
component:workflow-support-plugin imported-jira-issue pipeline priority:minor resolution:unresolved
Dominant language
Java
Stars
23
Forks
75
PR merge metrics
No merged PRs in 30d

Description

When using the environment directive in a declarative pipeline, the environment variables that are set are not captured and exposed via the RunWrapper.getBuildVariables method.

For example, the following pipeline will yield an empty Map after execution.

Jenkinsfile

pipeline {

environment {
MY_ENVVAR = "example"
}

stages {
stage("run job") {
steps {
sh 'printenv | sort'
}
}
}
}


Result

[:]


  

However, if we set this environment variable via the script directive it is captured and made available in the response of RunWrapper.getBuildVariables.

Jenkinsfile

pipeline {

stages {
stage("run job") {
steps {
script {
env.MY_ENVVAR = "example"
}

sh 'printenv | sort'
}
}
}
}


Result

[MY_ENVVAR:example]

 

I would expect that ALL custom set environment variables should be retrieved.

---
Originally reported by savepointsam, imported from: values set by environment directive are not captured for RunWrapper.getBuildVariables


  • status: Open
  • priority: Minor
  • component(s): workflow-support-plugin
  • label(s): pipeline, plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 2
  • imported: 20260601-173816

Raw content of original issue

When using the environment directive in a declarative pipeline, the environment variables that are set are not captured and exposed via the RunWrapper.getBuildVariables method.

For example, the following pipeline will yield an empty Map after execution.

Jenkinsfile



pipeline {

environment {
MY_ENVVAR = "example"
}

stages {
stage("run job") {
steps {
sh 'printenv | sort'
}
}
}
}



Result



[:]



  

However, if we set this environment variable via the script directive it is captured and made available in the response of RunWrapper.getBuildVariables.

Jenkinsfile



pipeline {

stages {
stage("run job") {
steps {
script {
env.MY_ENVVAR = "example"
}

sh 'printenv | sort'
}
}
}
}



Result



[MY_ENVVAR:example]


 

I would expect that ALL custom set environment variables should be retrieved.

  • environment: jenkins-2.190.2-1.1.noarch, workflow-support:3.3

Contributor guide

Open the contributing guide

Research direction

Start with RunWrapper.getBuildVariables in the workflow-support-plugin and reproduce the issue using the Jenkinsfile examples: compare an environment directive with setting env.MY_ENVVAR in a script directive. Done means custom variables set by the environment directive are included in the returned map, matching the script-directive result.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.