3 # The script starts in the root folder of the repo, which has the following outline
4 # We fetch the version information from version.properties, build docker files and
5 # do a docker push. Since the job will be run under Jenkins, it will have the Nexus
10 BUILD_ARGS="--no-cache"
13 DOCKER_REPOSITORY="nexus3.onap.org:10003"
14 IMAGE_NAME="${DOCKER_REPOSITORY}/${ORG}/${PROJECT}"
17 source version.properties
18 VERSION=$release_version
19 SNAPSHOT=$snapshot_version
20 STAGING=${release_version}-STAGING
21 TIMESTAMP=$(date +"%Y%m%dT%H%M%S")Z
24 if [ $HTTP_PROXY ]; then
25 BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
27 if [ $HTTPS_PROXY ]; then
28 BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
31 function log_ts() { # Log message with timestamp
32 echo [DEBUG LOG at $(date -u +%Y%m%d:%H%M%S)] "$@"
35 function get_artifact_version() {
36 log_ts Get Maven Artifact version from pom.xml
37 MVN_ARTIFACT_VERSION=`echo -e "setns x=http://maven.apache.org/POM/4.0.0 \n xpath /x:project/x:version/text() "| xmllint --shell conductor/pom.xml | grep content | sed 's/.*content=//'`
38 log_ts Maven artifact version for HAS is $MVN_ARTIFACT_VERSION
39 if [[ "$MVN_ARTIFACT_VERSION" =~ SNAPSHOT ]]; then
40 log_ts "REPO is snapshots";
43 log_ts "REPO is releases";
46 BUILD_ARGS+=" --build-arg REPO=${REPO}"
47 BUILD_ARGS+=" --build-arg MVN_ARTIFACT_VERSION=${MVN_ARTIFACT_VERSION}"
50 function build_image() {
51 log_ts Building Image in folder: $PWD with build arguments ${BUILD_ARGS}
52 docker build ${BUILD_ARGS} -t ${IMAGE_NAME}:latest conductor/docker
56 function push_image() {
57 if [[ "$REPO" == snapshots ]]; then
64 function push_snapshot_image(){
65 log_ts Tagging images: ${IMAGE_NAME}:\{${SNAPSHOT}-${TIMESTAMP},${SNAPSHOT}-latest\}
66 docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${SNAPSHOT}-${TIMESTAMP}
67 docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${SNAPSHOT}-latest
68 log_ts ... Tagged images
70 log_ts Pushing images: ${IMAGE_NAME}:\{${SNAPSHOT}-${TIMESTAMP},${SNAPSHOT}-latest\}
71 docker push ${IMAGE_NAME}:${SNAPSHOT}-${TIMESTAMP}
72 docker push ${IMAGE_NAME}:${SNAPSHOT}-latest
73 log_ts ... Pushed images
76 function push_staging_image(){
77 log_ts Tagging images: ${IMAGE_NAME}:\{${STAGING}-${TIMESTAMP},${STAGING}-latest\}
78 docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${STAGING}-${TIMESTAMP}
79 docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${STAGING}-latest
80 log_ts ... Tagged images
82 log_ts Pushing images: ${IMAGE_NAME}:\{${STAGING}-${TIMESTAMP},${STAGING}-latest\}
83 docker push ${IMAGE_NAME}:${STAGING}-${TIMESTAMP}
84 docker push ${IMAGE_NAME}:${STAGING}-latest
85 log_ts ... Pushed images