11#! /bin/bash
22
33debug () {
4- if [ -n " ${CONFIG_DEBUG_ENABLED} " ]; then
4+ if [ " ${CONFIG_DEBUG_ENABLED} " == " 1 " ]; then
55 echo " DEBUG: ${* } "
66 fi
77}
@@ -47,25 +47,22 @@ fetch_pipelines(){
4747 echo " Only blocking execution if running previous workflows on branch: ${CIRCLE_BRANCH} "
4848 pipelines_api_url_template=" https://circleci.com/api/v2/project/gh/${CIRCLE_PROJECT_USERNAME} /${CIRCLE_PROJECT_REPONAME} /pipeline?branch=${CIRCLE_BRANCH} "
4949
50- debug " DEBUG Attempting to access CircleCI API. If the build process fails after this step, ensure your CIRCLECI_USER_AUTH is set. "
50+ debug " Fetching piplines: ${pipelines_api_url_template} > ${pipeline_file} "
5151 fetch " ${pipelines_api_url_template} " " ${pipeline_file} "
52- echo " DEBUG API access successful"
5352}
5453
5554fetch_pipeline_workflows (){
5655 for pipeline in $( jq -r " .items[] | .id //empty" ${pipeline_file} | uniq)
5756 do
58- debug " Checking time of pipeline: ${pipeline} "
57+ debug " Fetching workflow information for pipeline: ${pipeline} "
5958 pipeline_detail=${tmp} /pipeline-${pipeline} .json
6059 fetch " https://circleci.com/api/v2/pipeline/${pipeline} /workflow" " ${pipeline_detail} "
6160 created_at=$( jq -r ' .items[] | .created_at' " ${pipeline_detail} " )
62- debug " Pipeline was created at: ${created_at} "
61+ debug " Pipeline's workflow was created at: ${created_at} "
6362 done
6463 jq -s ' [.[].items[] | select((.status == "running") or (.status == "created"))]' ${tmp} /pipeline-* .json > ${workflows_file}
65-
6664}
6765
68- # CIRCLE_BUILD_NUM is going to be for job, not for pipeline
6966load_current_workflow_values (){
7067 my_commit_time=$( jq " .[] | select (.id == \" ${CIRCLE_WORKFLOW_ID} \" ).created_at" ${workflows_file} )
7168 my_workflow_id=$( jq " .[] | select (.id == \" ${CIRCLE_WORKFLOW_ID} \" ).id" ${workflows_file} )
@@ -78,11 +75,6 @@ update_comparables(){
7875
7976 load_current_workflow_values
8077
81- # need to only get the workflows which are created or running
82-
83- # need to pull out the workflows that are failed, and stuff, we need to only look for running ones
84- # also need to make sure that job # and pipeline # are interchangable
85-
8678 echo " This job will block until no previous workflows have *any* workflows running."
8779 oldest_running_workflow_id=$( jq ' . | sort_by(.created_at) | .[0].id' ${workflows_file} )
8880 oldest_commit_time=$( jq ' . | sort_by(.created_at) | .[0].created_at' ${workflows_file} )
0 commit comments