Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Compare $CI_COMMIT_BRANCH to your desired branch name in rules: # .gitlab-ci.yml stages: - test - deploy # This job will run always. test-job: stage: test image: bash script:...
Answer
#1: Initial revision
Compare [`$CI_COMMIT_BRANCH`](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html) to your desired branch name in [`rules`](https://docs.gitlab.com/ee/ci/yaml/index.html#rules): ```yaml # .gitlab-ci.yml stages: - test - deploy # This job will run always. test-job: stage: test image: bash script: - echo Test successful! deploy-job: stage: deploy rules: # Run only in main branch - if: $CI_COMMIT_BRANCH == "main" image: bash script: - echo Deployed nothing! ``` More examples can be found from the [documentation](https://docs.gitlab.com/ee/ci/jobs/job_control.html).