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
23 if [ $HTTP_PROXY ]; then
24 BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
26 if [ $HTTPS_PROXY ]; then
27 BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
30 function log_ts() { # Log message with timestamp
31 echo [DEBUG LOG at $(date -u +%Y%m%d:%H%M%S)] "$@"
34 function get_artifact_version() {
35 log_ts Get Maven Artifact version from pom.xml
36 sudo apt-get install libxml2-utils
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 tag_image() {
57 log_ts Tagging images: ${IMAGE_NAME}:\{$SNAPSHOT-${TIMESTAMP},$STAGING-${TIMESTAMP},latest\}
58 docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${SNAPSHOT}-${TIMESTAMP}
59 docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${STAGING}-${TIMESTAMP}
60 docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:latest
61 log_ts ... Tagged images
64 function push_image(){
65 log_ts Pushing images: ${IMAGE_NAME}:\{$SNAPSHOT-${TIMESTAMP},$STAGING-${TIMESTAMP},latest\}
66 docker push ${IMAGE_NAME}:${SNAPSHOT}-${TIMESTAMP}
67 docker push ${IMAGE_NAME}:${STAGING}-${TIMESTAMP}
68 docker push ${IMAGE_NAME}:latest
69 log_ts ... Pushed images