
Optimizing shared GitLab pipelines enhances flexibility and maintainability. Users can easily customize pipeline behavior by implementing variables as configuration points without compromising the original intent. While temporary workarounds exist, contributing to open-source projects to improve shared pipeline structures is highly recommended, especially during events like Hacktoberfest.
A colleague seeks to modify the script section of a job in a shared GitLab pipeline, facing hardcoded configuration:
# https://gitlab.com/rlespinasse/foobar-shared-ci-templates/-/blob/main/pipeline-with-hardcoded-values.yml
test-branch:
stage: test
before_script:
- ls
script: # it's for the example, the script can be more complex
- ls ./wrong-folder
This rigid setup causes pipeline failure in their project:
# https://gitlab.com/rlespinasse/foobar-project/-/blob/main/.gitlab-ci.yml
include:
- project: 'rlespinasse/foobar-shared-ci-templates'
ref: HEAD
file:
- '/pipeline-with-hardcoded-values.yml'
$ ls ./wrong-folder
ls: cannot access './wrong-folder': No such file or directory
The optimal approach involves implementing variables as configuration points:
# https://gitlab.com/rlespinasse/foobar-shared-ci-templates/-/blob/main/pipeline-with-variables.yml
variables:
FOLDER_TO_TEST: wrong-folder
test-branch:
stage: test
before_script:
- ls
script:
- ls ./${FOLDER_TO_TEST}
This method allows for easy customization:
# https://gitlab.com/rlespinasse/foobar-project/-/merge_requests/2
include:
- project: 'rlespinasse/foobar-shared-ci-templates'
ref: HEAD
file:
- '/pipeline-with-variables.yml'
variables:
FOLDER_TO_TEST: folder
$ ls ./${FOLDER_TO_TEST}
some-file
In the meantime, one can override only the script part:
# https://gitlab.com/rlespinasse/foobar-project/-/merge_requests/1
include:
- project: 'rlespinasse/foobar-shared-ci-templates'
ref: HEAD
file:
- '/pipeline-with-hardcoded-values.yml'
test-branch:
stage: test
script:
- ls ./folder
$ ls ./folder
some-file
While functional, this temporary solution may lead to divergences and maintenance issues.
It's recommended to contribute to open source or innersource projects (especially during Hacktoberfest) by proposing the addition of variables. This would allow users to adapt shared pipeline behaviors to their needs while preserving the original intent.
You can explore the code on those repositories:
💡 Note This post was originally published on my personal blog.
gemmaI ported the whole Gemma-4 family — E2B, E4B, 12B, 31B, and the 26B-A4B MoE — to run on...
communityHey DEV, I'm Tobore. Let's actually connect. I've been on here for a while now, mostly writing and...
ai(yep, kinda clickbait, just for the funsies 😊) At the beginning of the year, I relaunched my...
aiMy laptop was sitting idle with the fan at full tilt. Nothing was running that I knew of. The culprit...
githubactionsI Built a Thing! TL;DR — Google Gemini-based Pull Request reviews and Issue Triaging for...
aiI've been hearing the word "harness" thrown around a lot lately. I assumed it just meant "the IDE" or...
Workflows from the Neura Market marketplace related to this DeepSeek resource