forked from demisto/content
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_artifacts.sh
More file actions
executable file
·43 lines (34 loc) · 1.14 KB
/
upload_artifacts.sh
File metadata and controls
executable file
·43 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# exit on errors
set -e
# Build uploads artifacts dir to artifacts bucket
BRANCH=${CI_COMMIT_BRANCH:-unknown}
ARTIFACTS_DIR=${ARTIFACTS_FOLDER:-artifacts}
if [[ ! -d "$ARTIFACTS_DIR" ]]; then
echo "Directory [$ARTIFACTS_DIR] not found. Nothing to upload. Skipping!"
exit 0
fi
if [[ -z "$(ls -A ${ARTIFACTS_DIR})" ]]; then
echo "Directory [$ARTIFACTS_DIR] is empty. Nothing to upload. Skipping!"
exit 0
fi
if [[ "$BRANCH" =~ pull/[0-9]+ ]]; then
echo "Running on remote fork. Skipping!"
exit 0
fi
if [[ -z "$CI_PIPELINE_ID" ]]; then
echo "CI_PIPELINE_ID not set aborting!"
exit 1
fi
if [[ -z "$GCS_ARTIFACTS_BUCKET" ]]; then
echo "GCS_ARTIFACTS_BUCKET not set aborting!"
exit 1
fi
if [[ ! -f "$GCS_ARTIFACTS_KEY" ]]; then
echo "GCS_ARTIFACTS_KEY not set aborting!"
exit 1
fi
gcloud auth activate-service-account --key-file=$GCS_ARTIFACTS_KEY > auth.out 2>&1
TARGET_PATH="content/$BRANCH/$CI_PIPELINE_ID"
echo "auth loaded. uploading files at: $ARTIFACTS_DIR to target path: $TARGET_PATH ..."
gsutil -m cp -z html,md,json,log,txt -r "$ARTIFACTS_DIR" "gs://$GCS_ARTIFACTS_BUCKET/$TARGET_PATH"