Merge changes from topics 'update_postbuildscript_invocation', 'upgrade_jjb_version...
[ci-management.git] / shell / docker-build.sh
1 #!/bin/bash
2 # Ensure we fail the job if any steps fail
3 # Do not set -u as DOCKER_ARGS may be unbound
4 set -e -o pipefail
5
6 FULL_DATE=`date +'%Y%m%dT%H%M%S'`
7 IMAGE_VERSION= $( xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" pom.xml | cut -c1-5 )
8
9 case $DOCKERREGISTRY in
10    '$DOCKER_REGISTRY:10004') DOCKER_TAG="$IMAGE_VERSION"-STAGING-"$FULL_DATE"Z
11       echo "Using tag $DOCKER_TAG"
12       ;;
13    '$DOCKER_REGISTRY:10003') DOCKER_TAG="$IMAGE_VERSION"-SNAPSHOT-"$FULL_DATE"Z
14       echo "Using tag $DOCKER_TAG"
15       ;;
16 esac
17
18 # Switch to the directory where the Dockerfile is
19 cd "$DOCKER_ROOT"
20
21 # DOCKERREGISTRY is purposely not using an '_' so as to not conflict with the
22 # Jenkins global env var of the DOCKER_REGISTRY which the docker-login step uses
23 IMAGE_NAME="$DOCKERREGISTRY/$DOCKER_NAME:$DOCKER_TAG"
24
25 # Build the docker image
26
27 # Allow word splitting
28 # shellcheck disable=SC2086
29 docker build $DOCKER_ARGS . -t $IMAGE_NAME | tee "$WORKSPACE/docker_build_log.txt"
30
31 # Write DOCKER_IMAGE information to a file so it can be injected into the
32 # environment for following steps
33 echo "DOCKER_IMAGE=$IMAGE_NAME" >> "$WORKSPACE/env_inject.txt"
34