Skip to content

Instantly share code, notes, and snippets.

@Voronenko
Created October 21, 2022 09:38
Show Gist options
  • Save Voronenko/ecced6e1568296fd3467a6caaf2dde33 to your computer and use it in GitHub Desktop.
Save Voronenko/ecced6e1568296fd3467a6caaf2dde33 to your computer and use it in GitHub Desktop.
Basic staff on cross repo launching the pipelines
- run:
name: Launch pipeline
command: |
curl --location --request POST 'https://circleci.com/api/v2/project/(vcs)/(org)/(project)/pipeline' \
--header 'Content-Type: application/json' \
-u "${CIRCLE_CI_API_TOKEN}:"
#!/bin/bash
echo "{'branch':'$1', 'parameters': {'test': true }}" | tr \' \" >> request.json
cat request.json
started_pipeline=$(curl -s -u $CIRCLE_CI_API_TOKEN: -X POST https://circleci.com/api/v2/project/(vcs)/(org)/(project)/pipeline \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d @request.json)
pipeline_id=$(echo $started_pipeline | jq .id | xargs)
if [ $pipeline_id == 'null' ]
then exit 1
fi
sleep 5
echo "Calling workflow for pipeline: $pipeline_id"
pipeline_status_resp=$(curl -s -u $CIRCLE_CI_API_TOKEN: https://circleci.com/api/v2/pipeline/$pipeline_id/workflow)
echo "$pipeline_status_resp"
pipeline_status=$(echo $pipeline_status_resp | jq '.items | .[0].status' | xargs)
echo "Pipeline $pipeline_id has status $pipeline_status, starting polling for status update"
while [ $pipeline_status == 'running' ]
do
printf '.'
sleep 20
pipeline_status_resp=$(curl -s -u $CIRCLE_CI_API_TOKEN: https://circleci.com/api/v2/pipeline/$pipeline_id/workflow)
pipeline_status=$(echo $pipeline_status_resp | jq '.items | .[0].status' | xargs)
done
echo "Pipeline $pipeline_id complete with status $pipeline_status"
if [ $pipeline_status == 'failed' ]
then exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment