Skip to content

Commit

Permalink
[FIXED JENKINS-48229] Use the agent's dir separator for Dockerfile path
Browse files Browse the repository at this point in the history
I'm not sure how to test this - the issue occurs when the master's
got different directory separators than the agent, which isn't
something I can easily do in a unit test.
  • Loading branch information
abayer committed Nov 28, 2017
1 parent 147204a commit 73f434e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Expand Up @@ -81,11 +81,15 @@ public String getActualDir() {
}

@Nonnull
public String getDockerfilePath() {
public String getDockerfilePath(boolean isUnix) {
StringBuilder fullPath = new StringBuilder();
if (!StringUtils.isEmpty(dir)) {
fullPath.append(dir);
fullPath.append(IOUtils.DIR_SEPARATOR);
if (isUnix) {
fullPath.append(IOUtils.DIR_SEPARATOR_UNIX);
} else {
fullPath.append(IOUtils.DIR_SEPARATOR_WINDOWS);
}
}
fullPath.append(getDockerfileAsString());
return fullPath.toString();
Expand Down
Expand Up @@ -72,15 +72,16 @@ class DockerPipelineFromDockerfileScript extends AbstractDockerPipelineScript<Do

private Closure buildImage() {
return {
def dockerfilePath = describable.getDockerfilePath(script.isUnix())
try {
def hash = Utils.stringToSHA1(script.readFile("${describable.getDockerfilePath()}"))
def hash = Utils.stringToSHA1(script.readFile("${dockerfilePath}"))
def imgName = "${hash}"
def additionalBuildArgs = describable.getAdditionalBuildArgs() ? " ${describable.additionalBuildArgs}" : ""
script.sh "docker build -t ${imgName}${additionalBuildArgs} -f \"${describable.getDockerfilePath()}\" \"${describable.getActualDir()}\""
script.sh "docker build -t ${imgName}${additionalBuildArgs} -f \"${dockerfilePath}\" \"${describable.getActualDir()}\""
script.dockerFingerprintFrom dockerfile: describable.dockerfilePath, image: imgName, toolName: script.env.DOCKER_TOOL_NAME
return script.getProperty("docker").image(imgName)
} catch (FileNotFoundException f) {
script.error("No Dockerfile found at ${describable.getDockerfilePath()} in repository - failing.")
script.error("No Dockerfile found at ${dockerfilePath} in repository - failing.")
return null
}
}
Expand Down

0 comments on commit 73f434e

Please sign in to comment.