How to access other files in a GitLab CI/CD component when including it
Asked Answered
S

1

11

GitLab has added the CI/CD components in their latest versions, and I would like to use it to build a sort of library to use in my projects. Except in some components I would like to include some files and scripts (Fastfile, Dockerfile etc..). In the document it clearly shows that a component can have multiple files : GitLab CI components documentation

But when I include my component like this :

include:
  - component: <domain>/<group>/<project>/build-android@feature-android
    inputs:
      image: android:jdk17-33-33.0.1
      bundle_id: com.example.com
      build_type: release
      flavor: staging

I do import the template but then it cannot the scripts and files that reside in the same component repository.

I tried to import the component like this, as the documentation states :

include:
  - component: <domain>/<group>/<project>/build-android@feature-android
    inputs:
      image: android:jdk17-33-33.0.1
      bundle_id: com.example.com
      build_type: release
      flavor: staging

But all I get is the yaml template without the files. I would like to get the files in the same component repository as well.

I am using Gitlab version 16.7

Spellman answered 11/1 at 16:13 Comment(0)
B
9

I do import the template but then it cannot the scripts and files that reside in the same component repository.

This is the intended behavior of components in GitLab 16.7. include: only includes the CI configuration(s), not the configuration files themselves and not any other files. That is: include:component: is not really much different at all than other include: keywords like include:project:.

In the document it clearly shows that a component can have multiple files

This might be a bit misleading. The documentation doesn't really explain how other files in the component directory might be used. As I see it, a component author might find it useful to include additional files in your component directories for some other purposes, for example to build a docker image (perhaps image(s) used as the image: in your component CICD configuration), files for testing your component, or to provide documentation for a component.

However, as of GitLab 16.7, no files are actually included into the workspace on disk just by adding an an include: of a component or other CI configuration.


That said, I think it's obvious why component authors would want to bundle other files or resources with your components, like how you seem to be intuitively expecting. If you want to do this, you might still have some options for this, even in GitLab 16.7. For example, you could create a docker image for your component which bundles the resource files you need or you could write steps into your component jobs/steps to retrieve those bundled resources at runtime (e.g., run git clone or curl as part of your component job steps to get those files).

I would hope that, in a future version of GitLab, this feature (or the upcoming CI steps feature) is expanded to provide more direct support for including other types of resource files like how you might have expected.

Becalm answered 11/1 at 18:6 Comment(2)
Thanks for your feedback, I just wanted to be sure, as you said the documentation can be misleading. I thought about retrieving the files manually using git or curl, but I had hoped that there was a better solution. Thanks againSpellman
A CI/CD component can include another CI/CD component(s) ?Abnormality

© 2022 - 2024 — McMap. All rights reserved.