1
1
#! /bin/bash
2
2
3
3
debug () {
4
- if [ -n " ${CONFIG_DEBUG_ENABLED} " ]; then
4
+ if [ " ${CONFIG_DEBUG_ENABLED} " == " 1 " ]; then
5
5
echo " DEBUG: ${* } "
6
6
fi
7
7
}
@@ -47,25 +47,22 @@ fetch_pipelines(){
47
47
echo " Only blocking execution if running previous workflows on branch: ${CIRCLE_BRANCH} "
48
48
pipelines_api_url_template=" https://circleci.com/api/v2/project/gh/${CIRCLE_PROJECT_USERNAME} /${CIRCLE_PROJECT_REPONAME} /pipeline?branch=${CIRCLE_BRANCH} "
49
49
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} "
51
51
fetch " ${pipelines_api_url_template} " " ${pipeline_file} "
52
- echo " DEBUG API access successful"
53
52
}
54
53
55
54
fetch_pipeline_workflows (){
56
55
for pipeline in $( jq -r " .items[] | .id //empty" ${pipeline_file} | uniq)
57
56
do
58
- debug " Checking time of pipeline: ${pipeline} "
57
+ debug " Fetching workflow information for pipeline: ${pipeline} "
59
58
pipeline_detail=${tmp} /pipeline-${pipeline} .json
60
59
fetch " https://circleci.com/api/v2/pipeline/${pipeline} /workflow" " ${pipeline_detail} "
61
60
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} "
63
62
done
64
63
jq -s ' [.[].items[] | select((.status == "running") or (.status == "created"))]' ${tmp} /pipeline-* .json > ${workflows_file}
65
-
66
64
}
67
65
68
- # CIRCLE_BUILD_NUM is going to be for job, not for pipeline
69
66
load_current_workflow_values (){
70
67
my_commit_time=$( jq " .[] | select (.id == \" ${CIRCLE_WORKFLOW_ID} \" ).created_at" ${workflows_file} )
71
68
my_workflow_id=$( jq " .[] | select (.id == \" ${CIRCLE_WORKFLOW_ID} \" ).id" ${workflows_file} )
@@ -78,11 +75,6 @@ update_comparables(){
78
75
79
76
load_current_workflow_values
80
77
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
-
86
78
echo " This job will block until no previous workflows have *any* workflows running."
87
79
oldest_running_workflow_id=$( jq ' . | sort_by(.created_at) | .[0].id' ${workflows_file} )
88
80
oldest_commit_time=$( jq ' . | sort_by(.created_at) | .[0].created_at' ${workflows_file} )
0 commit comments