I have two different projects. project1
and project2
. Inside project1
, I have file_project1
file:
apply:
stage: apply
script:
- bash folder/scripts/automation.sh
rules:
- if: $CI_PIPELINE_SOURCE == "push"
when: always
In project2
, I have created the .gitlab-ci.yml
and I have included the project1
and the file_project1
:
include:
- project: 'namespace/project1'
ref: main
file: 'file_project1'
During the execution, project2
does not recognize the folder/scripts/automation.sh
. I got the following error:
bash: folder/scripts/automation.sh: No such file or directory
Please, how can the pipeline inside project2
executes correctly the bash instruction defined in project1
?
1 Like
Hi the file folder/scripts/automation.sh doesnât exist in project2 and therefore doesnât recognize it. When you include yaml , it doesnât include other files in the project, just the yaml. You can try use Parent-child-pipeline so project2 will trigger the pipeline in project 1
1 Like
What you recommended for shared sh files between projects-components cicd ? (or no use sh files ??)
any full sample about it ?
o use sh functions only in YML ? How I build a Gitlab CI pipeline as a shared common library pipeline | by Nguyáť
n Hoà ng Minh Quân | Medium
Currently you will need to have the sh file exist in the project you run the pipeline. With include
(template components) you are merging a single file that is evaluated in the context of the pipelineâs project, not the component project.
CI/CD Steps is a new feature, currently âExperimentalâ, which will have the functionality you need. This is the docs link for CI/CD Steps CI/CD steps | GitLab
1 Like
Iâm awaiting a feature like this, too, at the moment I have a workaround using the package registry . The general gist is:
I create a âreleaseâ in project1âs workflow which:
Adds the extra files to an archive.
Puts the archive in the package registry.
Adds a link to the package to the release.
I add a template in project1 that contains a job to download the package (in before_script
), via the link provided in project1âs releases page.
I use the template in project2âs workflow to download the package.
Then the script can be run from project2.
It sounds convoluted, thatâs why Iâm hoping that âstepsâ are introduced soon.
See https://gitlab.com/stephematician/r-gitlab-ci for an example.
My troubleshooting:
shared library (YML files)
In this article, I will explain how to create a shared common library pipeline, it is a centralized repository of tools, libraries, andâŚ
Reading time: 6 min read
add or override steps when using include: (templates) and/or extends: and/or globals/default for before_script (after_script)
gitlab-ci, gitlab-ci.yml
Using anchors and reference tags
gitlab, gitlab-ci
Here is a video shows how to configure CI Components that can access other repository files by using CI Steps. https://youtu.be/qxTbeYXEQLM?feature=shared
You can use ci steps today to access local files and run them as scripts
Check our this new YouTube video https://youtu.be/qxTbeYXEQLM?si=uIWwwl4ttlALiKQ9
Iâd prefer some written summary instead of a video.