Builds and archives uds 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 reference in ARTIFACT_DIRECTORY
31 # uses softlinks in order to save space and time
32 # ARTIFACT_DIRECTORY contents will be pushed to Artifactory
33 for ARTIFACT in $ARTIFACT_PATHS
34 do
35   # Check if file exists before creating a softlink
36   if [ ! -f "$ARTIFACT" ]; then
37     echo "$ARTIFACT does not exist."
38     exit 1
39   fi
40
41   echo "----------------------------------------------------"
42   echo "Info: Copy $ARTIFACT into $ARTIFACT_DIRECTORY"
43   echo "----------------------------------------------------"
44   ln -sf $WORKSPACE/$ARTIFACT $ARTIFACT_DIRECTORY
45 done
46
47 cd $ARTIFACT_DIRECTORY
48
49 # Rename the artifacts to include SHA commit ids of the projects for traceability
50 # e.g. 6d3abef-d96bad4-catalog-be-1.6.1-SNAPSHOT.war
51 for ARTIFACT in *
52 do
53   echo "----------------------------------------------------"
54   echo "Info: Adding CommitIDs $COMMIT_IDS to $ARTIFACT filename"
55   echo "----------------------------------------------------"
56   mv "$ARTIFACT" "$COMMIT_IDS-$ARTIFACT"
57 done