Set Environment Variable Based on Branch

Our Capybara tests can run on PhantomJS and on Selenium. I want to have a situation when

  • master branch builds run them on Selenium
  • staging / feature branches builds run them on Phantom JS

I can do that by setting environment variable CAPYBARA_DRIVER. However, I don’t know how to set this variable conditionally (by checking CIRCLE_BRANCH). What I tried is this

    - case $CIRCLE_BRANCH in "master") CAPYBARA_DRIVER=selenium bundle exec rake test:subset ;; *) CAPYBARA_DRIVER=poltergeist bundle exec rake test:subset ;; esac:
      parallel: true
          - test/capybara/*_test.rb

But it of course doesn’t work (since rake test:subset is inside case). I don’t want to use test:post because I want to use Circle CI’s method of distributing tests across nodes.

Any help?


Did you find out how? Same question over here.

Partially. We kick of nightly builds on master using API. We scheduled this script to run at the same time everyday and it’s passing name of driver in build parameters




post_data=$(cat <<EOF
    "build_parameters": {
    "CAPYBARA_DRIVER": "selenium"

curl \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data "${post_data}" \
--request POST
1 Like

That looks like a great solution @rience, using the build parameters API is perfect for adding any additional constraints to your nightly build.

For anyone looking for more info, please refer to our nightly build docs.