'How to run yq command from included project in Gitlab?

I have two projects JWT and RELEASE-MGMT under the same group name in Gitlab.I have the pipelines as follows.

gitlab-ci.yml

JWT:

stages:
  - prjname
include:
  - project: 'testing-group/RELEASE-MGMT'
    ref: 'main'
    file:
      - '/scripts/testing-prj-name.yml'

RELEASE-MGMT:(/scripts/testing-prj-name.yml)

testyqcommand:
  stage: prjname
before_script:
    - pip3 install jq
    - pip3 install awscli
    - pip3 install yq
script:
    - pwd
    - ls -ltr
    - echo $CI_PROJECT_NAME
    - yq -r '.$CI_PROJECT_NAME.projectname' projectnames.yml

Getting the below error

yq: error: argument files: can't open './scripts/testing-service-name.yml': [Errno 2] No such file or directory: './scripts/testing-service-name.yml'

I was thinking since the two projects exists in the same group we can do this without using multi-project pipelines and also RELEASE-MGMT is the one that is included in all the microservices we have got.



Solution 1:[1]

include: is a logical mechanism in rendering a pipeline configuration. It won't actually bring any files to the workspace of the project running the pipeline.

If you want to run yq against a YAML file in another project, you'll have to clone the project first or otherwise retrieve the file as part of your CI job -- for example by using the files API or cloning the repo with the job token:

script:
  - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.example.com/<namespace>/<project>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1