Search code examples
gitcodeship

Different ENV variable for each deployment pipeline on Codeship


I have JS application that consumes REST API specified in API_HOST environment variable.

Application has two deployment pipelines configured on Codeship for each branch (develop, master). For each branch I would like to provide different REST endpoint URL stored in API_HOST. Currently I have API_HOST variable defined under Environment tab but it doesn't work as it's globally defined for all deployment pipelines. Exporting API_HOST variable within Custom Script doesn't work neither.

I want to provide different API_HOST environment variable for every single deployment pipeline. How can I achieve that?


Solution

  • Solved.

    Codeship exposes CI_BRANCH environment variable (among others as described here Environment Variables On Codeship) so I was able to export API_HOST variable manually depending on branch name in Test -> Setup Commands like this: if [ "$CI_BRANCH" = "develop" ]; then export API_HOST="..."; elif [ "$CI_BRANCH" = "master" ]; then export API_HOST="'...'"; else echo "Unrecognized branch name."; fi;

    Thanks Codeship support team!