Reputation: 3854
I am trying to exclude a specific branch production
from the gitlab pipeline in AutoDevOps, however I don't seen to be able to figure out the correct syntax. Here is what I have:
build:
stage: build
image: docker:19.03.1
variables:
DOCKER_TLS_CERTDIR: ""
services:
- docker:19.03.8-dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- |
if [[ -z "$CI_COMMIT_TAG" ]]; then
export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG}
export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_SHA}
else
export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE}
export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_TAG}
fi
# make and git needed to run makefiles
- apk add --update make
- apk add --update git
- make ci-build
- make ensure_project publish_artifact
rules:
# don't build on production - that is just a marker branch in git
- if: '$CI_COMMIT_BRANCH != "production"'
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
However, the pipeline still runs for production
. What am I doing wrong?
Upvotes: 2
Views: 1548
Reputation: 21
I have solved such task with this
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^dev$/'
Upvotes: 0
Reputation: 91
Could you try except instead of rules
except:
- production
Gitlab CI/CD Pipeline Configuration
Upvotes: 3