We currently store our CI configs in a separate project and use the settings in the UI to link them.
For various reasons we want to move to using a .gitlab-ci.yml in the repo itself that includes these files from the cicd repo.
My current attempt is (note that the existing company-backend/.gitlab-ci.yml works perfectly):
include:
- project: minigrid/cicd
ref: 'chore/run-quality-separately'
file:
- 'company-backend/.gitlab-ci.yml'
# Added this after error described below - these are defined in the included config
stages:
- TestAndBuild
- AdditionalLinting
- Deploy
- Validate
- ApproveQA
- Live
- PostJobs
Putting this into CI Lint is giving the following error:
I added the stages explicitly (as above) - which I wasnāt expecting to need to do since they are defined in the linked file - but still no luck.
My understanding from the docs is that the entire linked file is essentially merged with the .gitlab-ci.yml to create the yaml that runs. What am I missing?
Iāve omitted the included company-backend/.gitlab-ci.yml file since a) it works already and has been unchanged b) is 350+ lines
No I havenāt yet - I canāt figure out how to run this pipeline in such a way that it overrides the project settings (which I cannot change as it will disrupt my team). If you know of a way then I can definitely give it a whirl!
I was running it in the CI lint tool with āSimulateā checked - which I think should perform the inclusion
The leading slash doesnāt seem to make any difference.
chore/run-quality-separately is a branch. If I change it to something deliberately wrong then CI Lint recognises the missing ref.
Interestingly, pasting the included file into CI Lint also fails. So I suspect there are further configuration settings that are currently being provided by the project settings that I am failing to provideā¦
Interesting! So it sounds like this isnāt anything obvious, at least AFAICT.
I wonder what happens if you make a simple branch on that repo, like testci and remove everything in the .gitlab-ci.yml except a really simple job, like:
stages:
- test
test:
script:
- echo "Hello, world!"
Hopefully that will work fine, then Iād change the branch name from testci to chore/testci and see if that makes a difference.
If all of that works fine, then Iād guess itās something in your .gitlab-ci.yml that you are including. Itās hard to know what that would be, but you could try linting that file in its original minigrid/cicd project, and cutting out the stages and jobs that you arenāt using in the downstream project, and see if that lints OK.
If I remove <<: *automatically_builds or make it always resolve to true then it works fine. But with it I get the No stages / jobs for this pipeline. error.
Note that pasting this directly into CI Lint works fine, its only when included that it fails.
Iām not sure if this should be considered a bug with CI Lint or if Iām expecting too much. Maybe the file is really supposed to be considered invalid in these cases ĀÆ_(ć)_/ĀÆ
Yeah sorry that is what it is in the real file, and if I change to that in the minimal example it fails also.
I just changed it to the contrived example to test.
It passes if I update to - if: ' "merge_request_event" == "merge_request_event"'
Interesting! Your fragment there passes the lint for me.
The reason for my question is that GitLab has āMRā pipelines and ābranchā pipelines. You only want the MR pipelines, I think, so you probably want to say something like:
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID
when: always
- when: never
Just a quick follow-up to this. If I ask the lint to Simulate a pipeline created for the default branch the config does fail, because there is nothing in that fragment that will cause the build-push job to run on the default branch. It will pass if you change it to this: