Trying to pass two build arguments in Jenkinsfile.
Works with single --build-arg:
app = docker.build("myimg:${Version}", "--build-arg VERSION=${Version} --no-cache ."
But doesn't work with several:
app = docker.build("myimg:${Version}", "--build-arg VERSION=${Version} --build-arg CODEARTIFACT_TOKEN=${CODEARTIFACT_TOKEN} --no-cache ."
Output Error: "docker build" requires exactly 1 argument.
How can I pass two or more build arguments?
CodePudding user response:
Feels like it is something Jenkins expect from you.
Jenkins doc says
It is possible to pass other arguments to docker build by adding them to the second argument of the build() method. When passing arguments this way, the last value in the that string must be the path to the docker file and should end with the folder to use as the build context)
you should try adding -f ${dockerfile}
right before context .
so it looks like this
app = docker.build("myimg:${Version}", "--build-arg VERSION=${Version} --build-arg CODEARTIFACT_TOKEN=${CODEARTIFACT_TOKEN} --no-cache -f Dockerfile ."
assuming your Dockerfile is in current folder.
here is doc:
- List item
https://www.jenkins.io/doc/book/pipeline/docker/
CodePudding user response:
The problem was not in number of build-args but with CODEARTIFACT_TOKEN variable.
The CODEARTIFACT_TOKEN variable probably contained new lines.
Therefore this line fixed the issue:
CODEARTIFACT_TOKEN = CODEARTIFACT_TOKEN.trim()