Global jjb tag override for ONAP
[ci-management.git] / shell / docker-ts-tag-override.sh
1 #!/bin/bash
2
3 # ================================================================================
4 # Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
18
19 set -feu -o pipefail
20
21 echo "--> docker-ts-tag-override.sh"
22
23 # Get project version from pom.xml
24 version=`xmllint --xpath "//*[local-name()='project']/*[local-name()='version']/text()" $DOCKER_ROOT/pom.xml`
25 echo "INFO: version from pom file $version"
26
27 # Some pom has -SNAPSHOT or -STAGING under pom version, remove all text
28 version="${version//[^0-9.]/}"
29
30 # Get build TS for specifying in the tag
31 timestamp=$(date +%C%y%m%dT%H%M%SZ)
32
33 # Following the https://wiki.onap.org/display/DW/Independent+Versioning+and+Release+Process
34 # IndependentVersioningandReleaseProcess-StandardizedDockerTagging
35 # ONAP Tag requirement :  {imagename}:{semver}-SNAPSHOT-{timestamp}Z (from CIMAN-132)
36
37 if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
38   tag="${version}-SNAPSHOT-${timestamp}"
39 else
40   # Default to latest tag with TS if not conforming to semantic versioning
41   echo "WARN: version not complaint to sem-ver; tag defaulted to latest"
42   version=latest
43   tag="${version}-${timestamp}"
44 fi
45
46 echo "INFO: docker tag is $tag"
47
48 # Write DOCKER_IMAGE_TAG information to a file so it can be
49 # injected into the environment for following steps
50 echo "DOCKER_IMAGE_TAG=$tag" >> "$WORKSPACE/env_docker_inject.txt"