Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CircleCI: env variable depending on branch

Id like to set different value for environment variable in circle.yml depending on branch name.Is it possible?

What i have:

machine:
    environment:
         MYVAR:"VAL1"

What id like to have is to be able detect type of the branch (master or not) and assign respective value to the variable?

like image 773
ArkadyB Avatar asked May 26 '16 11:05

ArkadyB


People also ask

How do I set environment variables in CircleCI?

To set an environment variable in a step, use the environment key. Since every run step is a new shell, environment variables are not shared across steps. If you need an environment variable to be accessible in more than one step, export the value using BASH_ENV .

What is CIRCLE_SHA1?

CIRCLE_SHA1. (String) The SHA1 hash of the last commit of the current build. CIRCLE_TAG. (String) The name of the git tag, if the current build is tagged.

What is Bash_env?

The $BASH_ENV environment variable holds a string that holds the location of a file in the /tmp directory. This is used to pass values between steps in a CircleCI Job. Typically this is appended to and created within the same step: - run: echo "export MY_ENV_VAR=example" >> $BASH_ENV.

How do I use CircleCI context?

Restrict a context to a project . Navigate to the Organization Settings > Contexts page of your GitLab organization in the CircleCI web app . The list of contexts will be visible. Select the name of an existing context, or click the Create Context button if you want to use a new context.


1 Answers

See: Build Details

CIRCLE_BRANCH

The name of the Git branch being tested, e.g. ‘master’, if the build is running for a branch.

so, you can use CIRCLE_BRANCH ENV for detect current branch. After, you can add some logic in code for use MYVAR_xxx or MYVAR_yyy according to CIRCLE_BRANCH.

like image 170
avokhmin Avatar answered Sep 23 '22 21:09

avokhmin