Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash -x
# Exit immediately if a command exits with a non-zero status.
set -e
if [ "$1" == "" ]; then
echo "Usage: $0 env"
exit 1
fi
ENV=$1
SLUG=$2
PIPELINE_ID=""
WORKFLOW_ID=""
WORKFLOW_STATUS="running"
start_integration_test () {
CREATE_PIPELINE_OUTPUT=$(curl --silent -X POST \
"https://circleci.com/api/v2/project/${SLUG}/pipeline?circle-token=${CIRCLE_TOKEN}" \
-H 'Accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"branch": "master",
"parameters": {
"run_'${ENV}'_integration_tests": true,
"run_base_tests": false
}
}')
PIPELINE_ID=$(echo $CREATE_PIPELINE_OUTPUT | jq -r .id)
echo "The created pipeline is ${PIPELINE_ID}"
# Sleep till circle starts a workflow from this pipeline
# TODO(roopakv): Change this to a curl loop instead of a sleep
sleep 20
}
get_workflow_from_pipeline () {
GET_PIPELINE_OUTPUT=$(curl --silent -X GET \
"https://circleci.com/api/v2/pipeline/${PIPELINE_ID}?circle-token=${CIRCLE_TOKEN}" \
-H 'Accept: */*' \
-H 'Content-Type: application/json')
WORKFLOW_ID=$(echo $GET_PIPELINE_OUTPUT | jq -r .items[0].id)
echo "The created worlkflow is ${WORKFLOW_ID}"
echo "Link to workflow is"
echo "https://circleci.com/workflow-run/${WORKFLOW_ID}"
}
running_statuses=("running" "failing")
wait_for_workflow () {
while [[ " ${running_statuses[@]} " =~ " ${WORKFLOW_STATUS} " ]]
do
echo "Sleeping, will check status in 30s"
sleep 30
WORFLOW_GET_OUTPUT=$(curl --silent -X GET \
"https://circleci.com/api/v2/workflow/${WORKFLOW_ID}?circle-token=${CIRCLE_TOKEN}" \
-H 'Accept: */*' \
-H 'Content-Type: application/json')
WORKFLOW_STATUS=$(echo $WORFLOW_GET_OUTPUT | jq -r .status)
echo "The workflow currently has status - ${WORKFLOW_STATUS}."
done
if [ "$WORKFLOW_STATUS" == "success" ]; then
echo "Workflow was successful!"
exit 0
else
echo "Workflow did not succeed. Status was ${WORKFLOW_STATUS}"
exit 1
fi
}
# remove noise so set +x
set +x
start_integration_test
get_workflow_from_pipeline
wait_for_workflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.