jenkinsci / jenkinsci/docker-workflow-plugin

[JENKINS-43077] withEnv does not set some environment variables

Open
#487 10 comments 0 reactions 0 assignees View on GitHub
component:docker-workflow-plugin imported-jira-issue priority:major resolution:unresolved
Dominant language
Java
Stars
527
Forks
422
Avg merge
10m
Merged PRs (30d)
1

Description

I don't believe this is a duplicate of JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

 

I had a `withEnv` section that looked like:

def flowContext(cl) {

withEnv([
'npm_config_cache=npm-cache',
'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
'http_proxy=http://proxy.mycompany.com:8080',
'https_proxy=http://proxy.mycompany.com:8080',
'HTTP_PROXY=http://proxy.mycompany.com:8080',
'HTTPS_PROXY=http://proxy.mycompany.com:8080',
'PROXY_HOST=proxy.mycompany.com',
'PROXY_PORT=8080',
'no_proxy=.mycompany.com'
]) {
credentialsContext(cl)
}
}

def credentialsContext(cl) {
withCredentials([
usernamePassword(
credentialsId: 'service-account-user-pass',
passwordVariable: 'SVC_PASS',
usernameVariable: 'SVC_USER'
),
usernamePassword(
credentialsId: 'github-auth-token',
passwordVariable: 'GITHUB_TOKEN',
usernameVariable: 'GITHUB_USERNAME'
),
usernamePassword(
credentialsId: 'service-account-maven-artifactory-token',
passwordVariable: 'ARTIFACTORY_USER',
usernameVariable: 'ARTIFACTORY_TOKEN'
),
usernamePassword(
credentialsId: 'service-account-maven-artifactory-password',
passwordVariable: 'ARTIFACTORY_USER',
usernameVariable: 'ARTIFACTORY_PASSWORD'
),
string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')

]) {
cl()
}
}


The credentials context is another function that exports a few credentials into the environment.

All of the credentials would be there, but not all of the environment variables.

This would be executed within a docker container like so:

    stage('Node Build') {

docker.image(ciNode).inside() {
//Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
parallel(
"Root Npm Install/Build": {
flowContext {
sh('env')
sh('npm install')
sh('gulp')
}
},
"webapp/static Install/Build": {
flowContext {
echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
sh('cd src/main/webapp/static && npm install')
sh('cd src/main/webapp/static && grunt prod')
}
},
failFast: true
)
}
}


The sh('env') command within the flowContext would never show the no_proxy environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.

---
Originally reported by beepdog, imported from: withEnv does not set some environment variables


  • status: Open
  • priority: Major
  • component(s): docker-workflow-plugin
  • resolution: Unresolved
  • votes: 6
  • watchers: 12
  • imported: 2025-12-07

Raw content of original issue

I don't believe this is a duplicate of JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

 

I had a `withEnv` section that looked like:



def flowContext(cl) {

withEnv([
'npm_config_cache=npm-cache',
'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
'http_proxy=http://proxy.mycompany.com:8080',
'https_proxy=http://proxy.mycompany.com:8080',
'HTTP_PROXY=http://proxy.mycompany.com:8080',
'HTTPS_PROXY=http://proxy.mycompany.com:8080',
'PROXY_HOST=proxy.mycompany.com',
'PROXY_PORT=8080',
'no_proxy=.mycompany.com'
]) {
credentialsContext(cl)
}
}

def credentialsContext(cl) {
withCredentials([
usernamePassword(
credentialsId: 'service-account-user-pass',
passwordVariable: 'SVC_PASS',
usernameVariable: 'SVC_USER'
),
usernamePassword(
credentialsId: 'github-auth-token',
passwordVariable: 'GITHUB_TOKEN',
usernameVariable: 'GITHUB_USERNAME'
),
usernamePassword(
credentialsId: 'service-account-maven-artifactory-token',
passwordVariable: 'ARTIFACTORY_USER',
usernameVariable: 'ARTIFACTORY_TOKEN'
),
usernamePassword(
credentialsId: 'service-account-maven-artifactory-password',
passwordVariable: 'ARTIFACTORY_USER',
usernameVariable: 'ARTIFACTORY_PASSWORD'
),
string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')

]) {
cl()
}
}



The credentials context is another function that exports a few credentials into the environment.
All of the credentials would be there, but not all of the environment variables.

This would be executed within a docker container like so:



    stage('Node Build') {

docker.image(ciNode).inside() {
//Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
parallel(
"Root Npm Install/Build": {
flowContext {
sh('env')
sh('npm install')
sh('gulp')
}
},
"webapp/static Install/Build": {
flowContext {
echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
sh('cd src/main/webapp/static && npm install')
sh('cd src/main/webapp/static && grunt prod')
}
},
failFast: true
)
}
}



The sh('env') command within the flowContext would never show the no_proxy environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.

environment

```
Jenkins 2.32.3

BlueOcean 1.0.0-rc1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.