Using && in rules.
Hello everyone,
I am having issues setting up a very simple pipeline with only 2 jobs:
- Build Production
- Deploy Production
In my gitlab-ci I have the following in the rules:
build-image-prod:
stage: build-prod
image: docker
services:
- docker:dind
script:
- echo 'Hello Gitlab'
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_COMMIT_TAG
deploy-job-prod:
stage: deploy-prod
image:
name: bitnami/kubectl:latest
entrypoint: ['']
script:
- echo 'Hello Gitlab'
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_COMMIT_TAG
I was trying to setup that every time that a TAG is created from main branch will be executed. So I have decided to use with the next code but based on documentation I cannot use only and rules at the same time.
only:
- main
I though, good, let’s try the following rule:
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_COMMIT_TAG
But it triggers every time there is a merge request or a tag from main branch and the next code triggers nothing
rules:
- if: $CI_COMMIT_BRANCH == "main" && $CI_COMMIT_TAG
Is there another way to setup the pipeline that will run only when there is a tag from main?
Thanks a lot!