jenkinsci / docker-ssh-agent

Docker image for Jenkins agents connected over SSH
https://hub.docker.com/repository/docker/jenkins/ssh-agent
MIT License
179 stars 175 forks source link

Environment variable scoping in the Jenkinsfile could be improved #423

Closed lemeurherve closed 2 months ago

lemeurherve commented 3 months ago

Jenkins and plugins versions report

N/A

What Operating System are you using (both controller, and any agents involved in the problem)?

N/A

Reproduction steps

  1. Notice how environment variables are defined in the Jenkinsfile.

Expected Results

Appropriate scope to avoid repetition and mistakes.

Actual Results

DOCKERHUB_ORGANISATION is redefined in every matrix branch in the "Main" stage while it could be defined once at the "docker-ssh-agent" global stage level: https://github.com/jenkinsci/docker-ssh-agent/blob/bad064233ecebab858236cd141e39b06b5fdbf98/Jenkinsfile#L22-L41

VERSION and ON_TAG are defined in the Linux script while they could be defined at the "Deploy to DockerHub" stage level so they could be reused by the Windows script and so all environment variables are defined in a similar manner: https://github.com/jenkinsci/docker-ssh-agent/blob/bad064233ecebab858236cd141e39b06b5fdbf98/Jenkinsfile#L76-L96

To retrieve VERSION as environment variable from the Windows build.ps1 script, a retrieval like the following one should be added: https://github.com/jenkinsci/docker-ssh-agent/blob/bad064233ecebab858236cd141e39b06b5fdbf98/build.ps1#L35-L37

Having this and the new scoping would allow simplify the call for publishing Windows to powershell '& ./build.ps1 publish'

Anything else?

No response

Are you interested in contributing a fix?

Yes:

lemeurherve commented 2 months ago

Confirmed working with https://github.com/jenkinsci/docker-ssh-agent/releases/tag/5.41.0 built completed on trusted.ci.jenkins.io