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?
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 .
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With