Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct syntax for environment variable #244

Merged
merged 4 commits into from
Jan 28, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ class Docker implements Serializable {
}
}

String asEnv(String var) {
node {
script.isUnix() ? "$${var}" : "%${var}%"
viceice marked this conversation as resolved.
Show resolved Hide resolved
}
}

public Image build(String image, String args = '.') {
check(image)
node {
def commandLine = 'docker build -t "$JD_IMAGE" ' + args
def commandLine = 'docker build -t "' + asEnv('JD_IMAGE') + '" ' + args
script.withEnv(["JD_IMAGE=${image}"]) {
script."${shell()}" commandLine
}
Expand Down Expand Up @@ -122,11 +128,11 @@ class Docker implements Serializable {
docker.node {
def toRun = imageName()
docker.script.withEnv(["JD_ID=${id}", "JD_TO_RUN=${toRun}"]) {
if (toRun != id && docker.script."${docker.shell()}"(script: 'docker inspect -f . "$JD_ID"', returnStatus: true) == 0) {
if (toRun != id && docker.script."${docker.shell()}"(script: 'docker inspect -f . "' + docker.asEnv('JD_ID') + '"', returnStatus: true) == 0) {
// Can run it without registry prefix, because it was locally built.
toRun = id
} else {
if (docker.script."${docker.shell()}"(script: 'docker inspect -f . "$JD_TO_RUN"', returnStatus: true) != 0) {
if (docker.script."${docker.shell()}"(script: 'docker inspect -f . "' + docker.asEnv('JD_TO_RUN') + '"', returnStatus: true) != 0) {
// Not yet present locally.
// withDockerContainer requires the image to be available locally, since its start phase is not a durable task.
pull()
Expand All @@ -143,7 +149,7 @@ class Docker implements Serializable {
docker.node {
def toPull = imageName()
docker.script.withEnv(["JD_TO_PULL=${toPull}"]) {
docker.script."${docker.shell()}" 'docker pull "$JD_TO_PULL"'
docker.script."${docker.shell()}" 'docker pull "' + docker.asEnv('JD_TO_PULL') + '"'
}
}
}
Expand All @@ -170,7 +176,7 @@ class Docker implements Serializable {
docker.node {
def taggedImageName = toQualifiedImageName(parsedId.userAndRepo + ':' + tagName)
docker.script.withEnv(["JD_ID=${id}", "JD_TAGGED_IMAGE_NAME=${taggedImageName}"]) {
docker.script."${docker.shell()}" 'docker tag "$JD_ID" "$JD_TAGGED_IMAGE_NAME"'
docker.script."${docker.shell()}" 'docker tag "' + docker.asEnv('JD_ID') + '" "' + docker.asEnv('JD_TAGGED_IMAGE_NAME') + '"'
}
return taggedImageName;
}
Expand All @@ -182,7 +188,7 @@ class Docker implements Serializable {
// That's ok since tagging is cheap.
def taggedImageName = tag(tagName, force)
docker.script.withEnv(["JD_TAGGED_IMAGE_NAME=${taggedImageName}"]) {
docker.script."${docker.shell()}" 'docker push "$JD_TAGGED_IMAGE_NAME"'
docker.script."${docker.shell()}" 'docker push "' + docker.asEnv('JD_TAGGED_IMAGE_NAME') + '"'
}
}
}
Expand All @@ -201,13 +207,13 @@ class Docker implements Serializable {

public void stop() {
docker.script.withEnv(["JD_ID=${id}"]) {
docker.script."${docker.shell()}" 'docker stop "$JD_ID" && docker rm -f "$JD_ID"'
docker.script."${docker.shell()}" 'docker stop "' + docker.asEnv('JD_ID') + '" && docker rm -f "' + docker.asEnv('JD_ID') + '"'
}
}

public String port(int port) {
docker.script.withEnv(["JD_ID=${id}", "JD_PORT=${port}"]) {
docker.script."${docker.shell()}"(script: 'docker port "$JD_ID" "$JD_PORT"', returnStdout: true).trim()
docker.script."${docker.shell()}"(script: 'docker port "' + docker.asEnv('JD_ID') + '" "' + docker.asEnv('JD_PORT') + '"', returnStdout: true).trim()
}
}
}
Expand Down