Can Gitlab CI/CD Componentes include non-yml resources?

Problem to solve

*I’m trying to define a “complex” CI component that contains a series of configuration files, that are used via a python script that is also included in the component directory. As I understood the documentation, you can either define a simple component, which is just a yml file, or you can create a complex component, by including a whole folder, with a template.yml file. I have succeeded in defining a component in this way on our standalone gitlab server (version 16.8.1-ee) and it does execute. However when I add an “ls -al” in my script, I can’t see the component contents, so I can’t execute my python file, and I can’t use these configuration files.

  • What are you seeing, and how does that differ from what you expect to see?
  • Consider including screenshots, error messages, and/or other helpful visuals

Steps to reproduce

This is the directory structure of my component repositpory:

└── templates
    └── peer-review
        ├── config
        │   ├── contributors
        │   │   ├── gsd
        │   │   │   ├── backend-api
        │   │   │   │   └── contributors.toml
        │   │   │   └── frontend
        │   │   │       └── contributors.toml
        │   │   └── infra
        │   │       └── multi-prod
        │   │           └── contributors.toml
        │   └── slack
        │       └── slack_users.json
        ├── scripts
        │   ├── __init__.py
        │   └── merge_request_notifier.py
        ├── template.yml
        └── tests
            ├── __init__.py
            └── merge_request_notifier_tests.py

In my peer-review/template.yml I have the following code:

spec:
  inputs:
    stage:
      default: test
---
component-job:
  script:
    - echo job 1
    - ls -al
    - cat config/slack/slack_users.json
  stage: $[[ inputs.stage ]]

This is supposed to show how I can access the files defined under my component configuration from the host project.

I have set up a host project with the following .gitlab-ci.yml:

include:
  - component: example.gitlab.server/devops/common-gitlab-config/peer-review@~latest
    inputs:
      stage: build

THis does launch the pipeline and executes the component. Here is the log:

$ echo job 1
job 1
$ ls -al
total 28
drwxrwxrwx 3 root root 4096 May 29 13:45 .
drwxrwxrwx 4 root root 4096 May 29 13:45 ..
drwxrwxrwx 6 root root 4096 May 29 13:45 .git
-rw-rw-rw- 1 root root    6 May 29 13:45 .gitignore
-rw-rw-rw- 1 root root  124 May 29 13:45 .gitlab-ci.yml
-rw-rw-rw- 1 root root 6172 May 29 13:45 README.md
cat: config/slack/slack_users.json: No such file or directory
$ cat config/slack/slack_users.json
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1

how come I can’t see the files and folders included in my component configuration?

Configuration

See above

Versions

Please select whether options apply, and add the version information.

  • [ x] Self-managed
  • [ x] Self-hosted Runners

Versions

  • GitLab (16.8.1-ee):
  • GitLab Runner, if self-hosted (Don’t know):

This isn’t currently possibly unfortunately. You’d need to grab the files using something like curl or wget or build a docker image including the dependencies

See Support for "additional files" in CI templates/components (#439478) · Issues · GitLab.org / GitLab · GitLab

1 Like

I have been informed that steps should solve this: CI/CD Steps | GitLab

And I think this will be available from 17.1 :crossed_fingers:

I haven’t personally experimented with them yet- but i’m looking forward to it!

Here’s a rough idea of what it could look like:

spec:
  inputs:
    stage:
      default: test
---
component-job:
  run:
    - name: my_step
      step: .
  stage: $[[ inputs.stage ]]

Then the step would look like:

spec: {}
---
steps:
  - name: my_step
    script: |
      echo job 1
      ls -al
      cat ${{ step_dir }}/config/slack/slack_users.json
2 Likes