Issue
I have a Makefile in my project root folder. Among other commands is:
export DOCKER_REPO?=myRepo
export APP_NAME?=myApp
export VAR1?=foo
export VAR2?=bar
TAG?=$(shell git rev-list HEAD --max-count=1 --abbrev-commit)
pack: ## creates the docker image
docker build . -f ./build/Dockerfile \
--platform linux/amd64 \
--build-arg VAR1=$(VAR1) \
--build-arg VAR2=$(VAR2) \
-t $(DOCKER_REPO)/$(APP_NAME):$(TAG) \
-t $(DOCKER_REPO)/$(APP_NAME):latest
When I make pack
from a local machine, the command works fine.
When Jenkins executes it as part of a pipeline...
steps {
script {
sh "make pack"
// other stuff
}
}
... string vars are interpolated except for the last line!
The resulting command that's executed:
docker build . -f ./build/Dockerfile \
--platform linux/amd64 \
--build-arg VAR1=foo \
--build-arg VAR2=bar \
-t myRepo/myApp:8a49356
It misses -t myRepo/myApp:latest
completely.
I cannot figure it out. Should I escape/sanitize my TAG
var somehow?
Solution
My TAG
comes from
env.TAG = sh(script: "git rev-list HEAD --max-count=1 --abbrev-commit", returnStdout: true)
Appending a .trim()
fixed my issue.
Answered By - Fabio B.
Answer Checked By - Timothy Miller (JavaFixing Admin)