Start Building for Free
CircleCI.comBlogCommunitySupport

kelvintaywl/control-flow

A shareable package of CircleCI configuration to integrate with control-flow, written by kelvintaywl

Community
  • Orb Quick Start Guide
  • Usage Examples
    • sequential-workflow
  • Jobs
  • Commands
    • Executors
    • Orb Source
    1. Orbs
    2. kelvintaywl/control-flow@0.1.1

    kelvintaywl/control-flow@0.1.1

    Sections
    Collection of jobs and commands to help manipulate the order of workflows, jobs in your pipeline.
    Created: September 27, 2022Version Published: September 27, 2022Releases: 2
    Org Usage:
    < 25
    Homepage:
    https://github.com/kelvintaywl/control-flow-orb
    Source:
    https://github.com/kelvintaywl/control-flow-orb

    Orb Quick Start Guide

    Use CircleCI version 2.1 at the top of your .circleci/config.yml file.

    1 version: 2.1

    Add the orbs stanza below your version, invoking the orb:

    1 2 orbs: control-flow: kelvintaywl/control-flow@0.1.1

    Use control-flow elements in your existing workflows and jobs.

    Opt-in to use of uncertified orbs on your organization’s Security settings page.

    Usage Examples

    sequential-workflow

    Uses control-flow/approve-workflow job, an approval job to control the order between 2 workflows. In this example, we want to run workflow bbb only after aaa. We add an approval job (start) as the first job for workflow bbb. We then add the control-flow/approve-workflow job as the final job in workflow aaa. Essentially, workflow bbb is on-hold until workflow aaa approves the approval job in workflow bbb.

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 version: '2.1' orbs: flow: kelvintaywl/control-flow@0.1 jobs: noop: docker: - image: cimg/base:current resource_class: small steps: - run: echo "noop" workflows: aaa: jobs: - noop: name: build - flow/approve-workflow: workflow-name: bbb job-name: start requires: - build context: - circleci-api bbb: jobs: - start: type: approval - noop: name: deploy requires: - start

    Jobs

    approve-workflow

    Looks for and approve an approval job in a specific workflow in this current pipeline. Useful for forcing workflow XYZ to run only after workflow ABC. Assumes the approval job is at the start of workflow XYZ in this case. See the `sequential-workflow` example for more information. NOTE: this requires a valid CircleCI API token, and assumes this is available via the $CIRCLE_TOKEN environment variable.

    Show job Source
    PARAMETER
    DESCRIPTION
    REQUIRED
    DEFAULT
    TYPE
    workflow-name
    Name of the workflow to look up against. Assumes the workflow name is unique. Otherwise, it will look up the first workflow in this pipeline that matches this name.
    Required
    Name of the workflow to look up against. Assumes the workflow name is unique. Otherwise, it will look up the first workflow in this pipeline that matches this name.
    Yes
    -
    type: string
    string
    job-name
    Name of the approval job in workflow to approve. Assumes the job name is unique. Otherwise, it will look up the first approval job in the workflow that matches this name.
    Required
    Name of the approval job in workflow to approve. Assumes the job name is unique. Otherwise, it will look up the first approval job in the workflow that matches this name.
    Yes
    -
    type: string
    string

    Commands

    Executors

    Orb Source

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 # This code is licensed from CircleCI to the user under the MIT license. # See here for details: https://circleci.com/developer/orbs/licensing version: 2.1 description: | Collection of jobs and commands to help manipulate the order of workflows, jobs in your pipeline. display: home_url: https://github.com/kelvintaywl/control-flow-orb source_url: https://github.com/kelvintaywl/control-flow-orb commands: {} executors: default: docker: - image: cimg/base:current resource_class: small jobs: approve-workflow: description: | Looks for and approve an approval job in a specific workflow in this current pipeline. Useful for forcing workflow XYZ to run only after workflow ABC. Assumes the approval job is at the start of workflow XYZ in this case. See the `sequential-workflow` example for more information. NOTE: this requires a valid CircleCI API token, and assumes this is available via the $CIRCLE_TOKEN environment variable. parameters: workflow-name: type: string description: | Name of the workflow to look up against. Assumes the workflow name is unique. Otherwise, it will look up the first workflow in this pipeline that matches this name. job-name: type: string description: | Name of the approval job in workflow to approve. Assumes the job name is unique. Otherwise, it will look up the first approval job in the workflow that matches this name. executor: default steps: - run: name: Find Pipeline ID command: | curl -H "Circle-Token: $CIRCLE_TOKEN" "https://circleci.com/api/v2/workflow/${CIRCLE_WORKFLOW_ID}" > workflow.json PIPELINE_ID=$(jq -r '.pipeline_id' workflow.json) echo "Set current pipeline ID to PIPELINE_ID env var" echo "export PIPELINE_ID='${PIPELINE_ID}'" >> $BASH_ENV rm workflow.json - run: name: Find Workflow ID for << parameters.workflow-name >> command: | curl -H "Circle-Token: $CIRCLE_TOKEN" "https://circleci.com/api/v2/pipeline/${PIPELINE_ID}/workflow" > workflows.json WORKFLOW_ID=$(jq -r '.items | map(select(.name == "<< parameters.workflow-name >>")) | .[0].id' workflows.json) echo "Set target workflow ID to WORKFLOW_ID env var" echo "export WORKFLOW_ID='${WORKFLOW_ID}'" >> $BASH_ENV rm workflows.json - run: name: Find Job ID for << parameters.job-name >> command: | curl -H "Circle-Token: $CIRCLE_TOKEN" "https://circleci.com/api/v2/workflow/${WORKFLOW_ID}/job" > jobs.json APPROVAL_JOB_ID=$(jq -r '.items | map(select(.name == "<< parameters.job-name >>" and .type == "approval")) | .[0].id' jobs.json) echo "Set target approval job ID to APPROVAL_JOB_ID env var" echo "export APPROVAL_JOB_ID='${APPROVAL_JOB_ID}'" >> $BASH_ENV rm jobs.json - run: name: Approve << parameters.job-name >> job in << parameters.workflow-name >> workflow command: | curl -X POST -H "Circle-Token: $CIRCLE_TOKEN" "https://circleci.com/api/v2/workflow/${WORKFLOW_ID}/approve/${APPROVAL_JOB_ID}" | jq . examples: sequential-workflow: description: | Uses control-flow/approve-workflow job, an approval job to control the order between 2 workflows. In this example, we want to run workflow bbb only after aaa. We add an approval job (start) as the first job for workflow bbb. We then add the control-flow/approve-workflow job as the final job in workflow aaa. Essentially, workflow bbb is on-hold until workflow aaa approves the approval job in workflow bbb. usage: version: "2.1" orbs: flow: kelvintaywl/control-flow@0.1 jobs: noop: docker: - image: cimg/base:current resource_class: small steps: - run: echo "noop" workflows: aaa: jobs: - noop: name: build - flow/approve-workflow: workflow-name: bbb job-name: start requires: - build context: # ASSUMPTION: this org context provides a $CIRCLE_TOKEN env var # which contains a valid CircleCI API token as its value. - circleci-api bbb: jobs: - start: type: approval - noop: name: deploy requires: - start
    Developer Updates
    Get tips to optimize your builds
    Or join our research panel and give feedback
    By submitting this form, you are agreeing to ourTerms of UseandPrivacy Policy.