In my pipeline file I have the following...
pipelines:
tags:
'*.*.*-dev':
- step:
name: Build Base Image
script:
- echo ${DOCKERHUB_PASSWORD} | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
- docker pull ${IMAGE_NAME}:base
- docker build . --file base.Dockerfile --tag ${IMAGE_NAME}:base --tag ${IMAGE_NAME}:base-${BITBUCKET_TAG} --cache-from ${IMAGE_NAME}:base
- docker push "${IMAGE_NAME}:base"
- docker push "${IMAGE_NAME}:base-${BITBUCKET_TAG}"
services:
- docker
- step:
name: Build Final Image
script:
- echo ${DOCKERHUB_PASSWORD} | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
- docker build . --file Dockerfile --tag ${IMAGE_NAME}:latest --tag ${IMAGE_NAME}:${BITBUCKET_TAG} --build-arg IMAGE_NAME="${IMAGE_NAME}:base-${BITBUCKET_TAG}" --build-arg BITBUCKET_TAG="${BITBUCKET_TAG}"
- docker push "${IMAGE_NAME}:latest"
- docker push "${IMAGE_NAME}:${BITBUCKET_TAG}"
services:
- docker
And in the dockerfile...
ARG IMAGE_NAME
ARG BITBUCKET_TAG
FROM $IMAGE_NAME
...other build stuff
ENV API_REV_VERSION=${BITBUCKET_TAG}
For reference, IMAGE_NAME seems to work just fine in the image, (but only with the syntax above).
However, even though I can confirm that BITBUCKET_TAG is not empty, because it only runs when it's not, the environment variable shows up as null in the final image. (Running env
in shell shows API_REV_VERSION=
on its own line)
Why would the env variable not get set properly?