jenkinsci / jenkinsci/docker-workflow-plugin
[JENKINS-41395] docker.build() should sanitize input for newlines
- Dominant language
- Java
- Stars
- 527
- Forks
- 422
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Description
Using the following basic Jenkinsfile I accidentally broke all my docker.build() invocations in a very difficult to grok bug.
node('docker') {
/* Make sure we're starting with a pristine workspace */
deleteDir()String imageName = 'jenkinsciinfra/terraform'
String commitHash
def container = nullstage('Checkout') {
checkout scm
commitHash = sh(returnStdout: true, script: 'git rev-parse --short origin/master')
}stage('Build') {
container = docker.build("${imageName}:${commitHash}")
}
}
This would fail with:
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] sh
[terraform] Running shell script
+ docker build -t jenkinsciinfra/terraform:f84fd39
"docker build" requires exactly 1 argument(s).
See 'docker build --help'.Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
[Pipeline] }
[Pipeline] // stage
The problem here is that the commitHash has a newline character hidden at the end of it; the fix is obviously to add .trim(), but the fact that docker.build() doesn't sanitize the imageName parameter means that the user isn't provided any useful feedback when the invalid input breaks the command.
I would suggest either sanitizing the imageName input, or run some validation to ensure that imageName is valid.
---
Originally reported by
rtyler, imported from: docker.build() should sanitize input for newlines
Raw content of original issue
Using the following basic Jenkinsfile I accidentally broke all my docker.build() invocations in a very difficult to grok bug.
node('docker') {
/* Make sure we're starting with a pristine workspace */
deleteDir()String imageName = 'jenkinsciinfra/terraform'
String commitHash
def container = nullstage('Checkout') {
checkout scm
commitHash = sh(returnStdout: true, script: 'git rev-parse --short origin/master')
}stage('Build') {
container = docker.build("${imageName}:${commitHash}")
}
}This would fail with:
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] sh
[terraform] Running shell script
+ docker build -t jenkinsciinfra/terraform:f84fd39
"docker build" requires exactly 1 argument(s).
See 'docker build --help'.Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
[Pipeline] }
[Pipeline] // stageThe problem here is that the commitHash has a newline character hidden at the end of it; the fix is obviously to add .trim(), but the fact that docker.build() doesn't sanitize the imageName parameter means that the user isn't provided any useful feedback when the invalid input breaks the command.
I would suggest either sanitizing the imageName input, or run some validation to ensure that imageName is valid.
Contributor guide
Assessment
This issue has not been assessed yet.