4.0 KiB
CI/CD pipeline
Refer to CI/CD pipelines and CI/CD pipeline templates.
Also check Use CI/CD configuration from other files and Use extends to reuse configuration sections.
Specify when to run jobs
Refer Specify when jobs run with rules.
Use the rules key and specify the conditions the job needs.
The
only/exceptkeywords have been deprecated by theruleskeyword, and cannot be used together.
This means one might be forced to useonly/exceptif one is including a pipeline that is already using them.
Conditions are validated in order until one applies. The rest are ignored.
If no condition applies, the job is skipped.
The default condition is on_success.
Run when some specific files change:
docker-build:
rules:
- changes:
- cmd/*
- go.*
- Dockerfile
docker-run:
only:
changes:
- cmd/*
- …
Multiple entries in the changes condition are validated in an OR fashion. In the example above, the condition will make the
job run only when a change occurs:
- to any file in the
cmddirectory - to any file in the repository's root directory which name starts with
go(likego.modorgo.sum) - to the
Dockerfilein the repository's root directory
Run on schedules:
docker-build:
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
docker-run:
only:
- schedule
Refer Using GitLab scheduled pipelines simplified 101 to configure and activate schedules.
Only run on specific events:
docker-build:
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- # Disable for all other conditions
when: never
Run on all conditions except specific ones:
docker-build:
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
when: never
Troubleshooting
Pipeline fails with error You are not allowed to download code from this project
Error message example:
Getting source from Git repository 00:00
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /builds/myProj/myRepo/.git/
remote: You are not allowed to download code from this project.
fatal: unable to access 'https://gitlab.com/myProj/myRepo.git/': The requested URL returned error: 403
Root cause: the user starting the pipeline does not have enough privileges to the repository.
Solution: give that user developer access or have somebody else with enough privileges run it.