This article is about Codeship Basic.

Ignore command on specific branch or run only on a branch

Estimated Reading Time: 1 min

What is including or excluding a specific branch?

For a variety of reasons, you may want to either only run commands on certain branches (i.e. only run custom alert commands on the master branch) or exclude commands from running on certain branches (i.e. never run acceptance tests if on a branch that starts with feature/*).

Below you will find scripts that you can use on your project’s setup and test commands to accomplish both scenarios.

Using Include / Exclude Commands Per Branch

Skip A Command On Specific Branches

If you don’t want to run a command on a specific branch use the following syntax. In this example we run your command on every branch except gh_pages

if [ "$CI_BRANCH" != "gh-pages" ]; then YOUR_COMMAND; fi

Only Run A Command On Specific Branches

If you want to run a specific command only on one branch use the following syntax. In this example we run your command only on the master branch.

if [ "$CI_BRANCH" == "master" ]; then YOUR_COMMAND; fi

Need More Help?

Get in touch if you need more help, or post on Stack Overflow using the tag #Codeship.

  • Ask The Helpdesk A Question
  • Code Examples And Sample Projects
    • Was This Article Helpful?