I'm trying to build a job that can be conditionally executed depends on whether the files or subdirectories in WebClient
is modified in develop
branch, using rules
. If there are changes found in the develop branch only, then a pipeline will be built.
Currently what I got in my .gitlab-ci.yml
is
deploy_dev_client:
stage: client
tags:
- my tags
script:
- '& cd WebClient'
- 'npm rebuild node-sass'
- 'npm install @angular/[email protected]'
- '& npm run build-release --max_old_space_size=$NODE_MEMORY_SIZE'
rules:
- changes:
- WebClient/**/*
when: always
- when: never
However, after testing, I realized that the pipeline is executed whenever I push something from my local repo to gitlab, even at the other side branches.
I have tried using only:-develop'
, however it results in yaml invalid
error, maybe due to not being able to use only
if rules
has already been used. Is there anyway I can still using rules
to target only develop
branch?
In this link:
https://docs.gitlab.com/ee/ci/yaml/#ruleschanges
They write that rules: changes
should work exactly like only/except
. If you read about only/except
, there are a few strange things with it:
https://docs.gitlab.com/ee/ci/yaml/#using-onlychanges-without-pipelines-for-merge-requests
When pushing a new branch or a new tag to GitLab, the policy always evaluates to true.
To get around this and only run your job on the development branch, you should be able to combine an if
with changes
:
deploy_dev_client:
stage: client
tags:
- my tags
script:
- '& cd WebClient'
- 'npm rebuild node-sass'
- 'npm install @angular/[email protected]'
- '& npm run build-release --max_old_space_size=$NODE_MEMORY_SIZE'
rules:
- if: '$CI_COMMIT_REF_NAME== "development"'
changes:
- WebClient/**/*
when: always
(I haven't tested this code, so let me know if it is all wrong!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With