Docker Community Forums

Share and learn in the Docker community.

Passing variables to an automated build - DOCKER_TAG

I have a project with auto-builds set up for each major branch.

Now I would like to be able to trigger an auto-build that will overlay a branch with code from a pull request.

The following page mentions a variable DOCKER_TAG that is passed to a build.

Is there a way to access this variable within my Dockerfile?

Here is what I hope to do.

# Assign the env variable DOCKER_TAG to an arg of the same name


# if DOCKER_TAG is in the format prNNNN then merge code for that PR on top of the current branch
RUN PRNUM=`echo ${DOCKER_TAG}| egrep "^pr([0-9]+)$" | sed -e s/pr//` && \
    if [ -n "$PRNUM" ]; \ 
    then echo "Merging $PRNUM"; \
      curl -o /tmp/pr.patch -L$PRNUM.diff; \
      git apply /tmp/pr.patch; \

Is this possible? Can you offer any advice on this issue?

I have also posted the issue here:

1 Like

I found a solution that seems to work. I created a build hook names hooks/build and pass the variable explicitly.

docker build --build-arg DOCKER_TAG=$DOCKER_TAG -f $DOCKERFILE_PATH -t $IMAGE_NAME .