DEV Community

Ken Collins for Custom Ink Technology

Posted on

3

Trigger CircleCI Workflow. AKA Simple Deploy Button

Very simple, no parameters needed, no enums, no booleans... just a really easy way to trigger a deploy with CircleCI. We can do this making use of the trigger_source pipeline value. When you click the button in CircleCI to "Trigger Pipeline" the value would be api vs something like webhook.



version: 2.1
jobs:
  deploy:
    machine:
      image: ubuntu-2204:current
    steps:
      - run: echo 'Deploying...'
workflows:
  deploy:
    when: { equal: [ api, << pipeline.trigger_source >> ] }
    jobs:
      - deploy


Enter fullscreen mode Exit fullscreen mode

If your workflow needs a test job, consider doing something a bit more complicated. Here we use two when conditions to work with a parameter.



version: 2.1
parameters:
  workflow:
    type: enum
    default: test
    description: The workflow to trigger.
    enum: [test, deploy]
jobs:
  test-job:
    machine:
      image: ubuntu-2204:current
    steps:
      - run: echo 'Testing...'  
  deploy-job:
    machine:
      image: ubuntu-2204:current
    steps:
      - run: echo 'Deploying...'
workflows:
  test:
    when: { equal: [ test, << pipeline.parameters.workflow >> ] }
    jobs:
      - test-job
  deploy:
    when: { equal: [ deploy, << pipeline.parameters.workflow >> ] }
    jobs:
      - deploy-job


Enter fullscreen mode Exit fullscreen mode

Now your CircleCI config will run tests by default and you can easily trigger a deploy via any branch using the "Trigger Pipeline" button.

Screen capture of the CircleCI application. This shows the trigger pipeline UI which has the Add Parameter disclosure open. The options Parameter type, Name, and Value have been set to string, workflow, deploy.

đź‘‹ While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay