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.
How to run Gitlab CI jobs only in specific branches?
+5
−0
By default Gitlab CI jobs run on any commit. I would like to restrict some of them to run only on commits to specific branches. How to do this in .gitlab-ci.yml
?
1 answer
+4
−0
Works for me
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
milohax | (no comment) | May 24, 2024 at 11:43 |
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:
- 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.
0 comment threads