Fix for the collecting of artifacts
[infra/cicd.git] / jjb / onap / uds / scripts / collect-artifacts.sh
1 #!/bin/bash
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2020 The Nordix Foundation. All rights reserved.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19
20 set -o errexit
21 set -o nounset
22 set -o pipefail
23
24 # Make directory to hold file artifacts (.war .jar etc)
25 mkdir -p $ARTIFACT_DIRECTORY
26
27 # Ensure at root of $WORKSPACE
28 cd $WORKSPACE
29
30 # For each file artifact create a copy in ARTIFACT_DIRECTORY
31 # ARTIFACT_DIRECTORY's contents will be pushed to Artifactory
32 # Required because artifacts in target directories will be deleted during a mvn clean
33 # which is done before archiving the source repos in order limit file size
34 for ARTIFACT in $ARTIFACT_PATHS
35 do
36   # Check if file exists before copying
37   if [ ! -f "$ARTIFACT" ]; then
38     echo "$ARTIFACT does not exist."
39     exit 1
40   fi
41
42   echo "----------------------------------------------------"
43   echo "Info: Copy $ARTIFACT into $ARTIFACT_DIRECTORY"
44   echo "----------------------------------------------------"
45   cp $WORKSPACE/$ARTIFACT $ARTIFACT_DIRECTORY
46 done
47
48 cd $ARTIFACT_DIRECTORY
49
50 # Rename the artifacts to include SHA commit ids of the projects for traceability
51 # e.g. 6d3abef-d96bad4-catalog-be-1.6.1-SNAPSHOT.war
52 for ARTIFACT in *
53 do
54   echo "----------------------------------------------------"
55   echo "Info: Adding CommitIDs $COMMIT_IDS to $ARTIFACT filename"
56   echo "----------------------------------------------------"
57   mv "$ARTIFACT" "$COMMIT_IDS-$ARTIFACT"
58 done