jenkinsci / jenkinsci/docker-plugin

Node environment properties don't get precedence over global settings

Open
#664 0 comments 5 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
498
Forks
324
Avg merge
1d 2h
Merged PRs (30d)
2

Description

Hi 👋

#### The environment I'm working in
* Jenkins: `2.121.1`
* docker-plugin: `1.1.4`
* `docker version`
```
Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:20:16 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm

Server:
Engine:
Version: 18.03.1-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:23:58 2018
OS/Arch: linux/amd64
Experimental: false
```

#### My problem
I'm trying to set up ephemeral build agents and I noticed that environment properties set on node-level don't get precedence over global properties. If an environment variable is defined on node-level only it is taken into account. But not otherwise. I'd expect that properties defined on a "more detailed" level take precedence.

To illustrate this (in my opinion) bug, here's what I configured.

##### Configure Jenkins > Global properties
![image](https://user-images.githubusercontent.com/3597890/41782235-f6c1059e-7639-11e8-9d0c-2309b7e28814.png)

##### Configure Jenkins > Cloud > Docker > Docker Agent templates > Node properties
![image](https://user-images.githubusercontent.com/3597890/41782615-09a90354-763b-11e8-8ccc-cd31a5d7ad2d.png)

The following pipeline running in my Docker container (based on the official [`jenkinsci/ssh-slave`](https://hub.docker.com/r/jenkinsci/ssh-slave/) image) reproduces this behaviour:

```groovy
pipeline {
agent {
label 'docker'
}

options {
buildDiscarder(logRotator(numToKeepStr: '10'))
disableConcurrentBuilds()
timeout(time: 10, unit: 'MINUTES')
gitLabConnection('gitlab.mycompany.com')
timestamps()
ansiColor('xterm')
}

stages {
stage('Reproduce bug') {
steps {
echo "ENV_AVAILABLE_ON_GLOBAL_AND_NODE_LEVEL=${env.ENV_AVAILABLE_ON_GLOBAL_AND_NODE_LEVEL}"
echo "ENV_AVAILABLE_ONLY_ON_NODE_LEVEL=${env.ENV_AVAILABLE_ONLY_ON_NODE_LEVEL}"
}
}
}
}
```

Result:
```
Started by user Brueckner, Marcel
Obtained Jenkinsfile from git URL/to/repository.git
Running in Durability level: PERFORMANCE_OPTIMIZED
[Pipeline] node
Running on docker-a3dbc9925324c on hostname.mycompany.com in /home/jenkins/workspace/jenkins-ephemeral-agent-build
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
...
[Pipeline] stage
[Pipeline] { (Reproduce bug)
[Pipeline] echo
16:58:34 ENV_AVAILABLE_ON_GLOBAL_AND_NODE_LEVEL=GLOBALVALUE
[Pipeline] echo
16:58:34 ENV_AVAILABLE_ONLY_ON_NODE_LEVEL=NODEVALUE
[Pipeline] }
[Pipeline] // stage
...
[Pipeline] End of Pipeline
Finished: SUCCESS
```

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.