Add schedule * Add schedule * Merged develop into feature/schedule Approved-by: Rachit Bhargava
84 lines
3.9 KiB
Bash
84 lines
3.9 KiB
Bash
#!/bin/bash
|
|
|
|
exec > >(tee -a script.log) 2>&1
|
|
|
|
# Install the required packages #
|
|
# --------------------------------------------------------------
|
|
apk upgrade && apk add --update curl wget zip unzip coreutils
|
|
|
|
cat schedule-setenv.sh && . ./schedule-setenv.sh
|
|
|
|
opt=$1
|
|
|
|
case $opt in
|
|
|
|
create-schedule-pipelines)
|
|
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
#curl --request POST --url "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pipelines_config/schedules" --header "Authorization: Bearer $TOKEN" --header 'Accept: application/json' --header "Content-Type: application/json" --data { \"type\": \"pipeline_schedule\", \"enabled\": true, \"target\": { \"ref_type\": \"branch\", \"type\": \"pipeline_ref_target\", \"ref_name\": \"$BRANCH_NAME\", \"selector\": { \"type\": \"custom\", \"pattern\": \"$PIPELINE_NAME\" } }, \"cron_pattern\": \"$CRONTIME\" }
|
|
# -----------------------------------------------------------------------------------
|
|
|
|
|
|
curl -X POST https://api.bitbucket.org/2.0/repositories/connectamerica/100plus-web/pipelines_config/schedules -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: Bearer $TOKEN" -d "{
|
|
\"type\": \"pipeline_schedule\",
|
|
\"enabled\": true,
|
|
\"target\": {
|
|
\"ref_type\": \"branch\",
|
|
\"type\": \"pipeline_ref_target\",
|
|
\"ref_name\": \"$BRANCH_NAME\",
|
|
\"selector\": {
|
|
\"type\": \"custom\",
|
|
\"pattern\": \"$PIPELINE_NAME\"
|
|
}
|
|
},
|
|
\"cron_pattern\": \"$CRONTIME\"
|
|
}"
|
|
|
|
|
|
|
|
echo "" && echo -----------------------------------
|
|
|
|
cat script.log | egrep -v "Errors:|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|Permission denied|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
|
|
|
;;
|
|
|
|
delete-schedule-pipelines)
|
|
|
|
for i in `curl -s --request GET --url "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pipelines_config/schedules" --header "Authorization: Bearer $TOKEN" --header 'Accept: application/json'| jq ".values[].target.selector.pattern+.values[].uuid" |awk -F'["{}]' '{print $3}'| uniq`
|
|
|
|
do
|
|
|
|
echo curl --location -g --request DELETE --url \'https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pipelines_config/schedules/{$i}\' --header \'Authorization: Bearer $TOKEN\' > delete.sh
|
|
|
|
chmod 755 delete.sh && ./delete.sh
|
|
|
|
done
|
|
|
|
cat script.log | egrep -v "Errors:|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|Permission denied|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
|
|
|
;;
|
|
|
|
|
|
list-schedule-pipelines)
|
|
|
|
echo "" && echo ----------------------------------------------
|
|
|
|
curl -s --request GET --url "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pipelines_config/schedules" --header "Authorization: Bearer $TOKEN" --header 'Accept: application/json' | jq .
|
|
|
|
echo ""
|
|
|
|
cat script.log | egrep -v "Errors:|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|Permission denied|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
|
|
|
;;
|
|
|
|
*)
|
|
echo "script for schedule-pipelines"
|
|
echo "Usage: schedule-pipeline.sh {create-schedule-pipelines|delete-schedule-pipelines}"
|
|
echo "create-schedule-pipelines : create-schedule-pipelines"
|
|
echo "delete-schedule-pipelines : delete-schedule-pipelines"
|
|
echo "list-schedule-pipelines : list-schedule-pipelines"
|
|
|
|
;;
|
|
esac
|