CircleCI – Conditional based on ENV Vars

We are migrating from Jenkins, to CircleCI for our image builds.

Our developers fork our repo's.

So we tag images 1 of 3 ways.

fork-name-gitsha <-- forked pull
repo-gitsha. <-- Pull from our actual repo
repo-branch-gitsha <- Merge to Master

In Circle CI, a Forked pull request contains this ENV Var.


But Pull requests from the main repo, or merges to master do not contain this.

Is there a way to do a conditional in CircleCI, based on an ENV var? I can only find examples for parameters.

basically something like..

  - when:
      condition: $CIRCLE_PR_USERNAME
        - run:
            name: Set FULL_IMAGE_NAME
            command: echo 'export FULL_IMAGE_NAME="${CIRCLE_CI_AWS_ACCOUNT_ID}/<< parameters.respository >>:${CIRCLE_PR_USERNAME}-${CIRCLE_SHA1:0:7}"' >> $BASH_ENV
        - run:
            name: Set IMAGE_TAG
            command: echo 'export IMAGE_TAG="${CIRCLE_CI_AWS_ACCOUNT_ID}/<< parameters.respository >>:${CIRCLE_PR_USERNAME}-${CIRCLE_SHA1:0:7}"' >> $BASH_ENV

Read more here:

Content Attribution

This content was originally published by Justin S at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: