Component with array input that supports concatenation

Problem to solve

When using a component, I’d like to use an array input, specifically for the tags used by the runner, and then check for the existence of a tag that should always exist. If that tag does not exist, I’d like to add it,

I’m wondering if it would even be possible. CI/CD Steps seems like it may support this use case as it allows for inputs and outputs. The caveat being I’m not sure if the job would start if the job that calls the steps uses the step output for the tags as its initially missing the required tags? Just wondering if anyone has run into this or has alternate solutions.

Steps are still considered experimental and we would prefer not to use them until they are stable and in less of a state of flux. The goal is just to be able to validate the input array, and append to it if necessary.

Configuration

Below is a small example truncated for brevity. We have a working component, but would like to automate the default tag if possible

The component spec:

spec:
  inputs:
    build_docs_folder:
      description: "The folder containing the generated HTML documentation."
      default: "${CI_PROJECT_DIR}/docs/"
     ... # removed for example
    python_image_tag:
      description: "Python image tag"
      default: 3.11-slim
    tags:
      default: []
      type: array
      description: List of tags

The component yaml:

build_docs:
  image: python:$[[ inputs.python_image_tag ]]
  stage: $[[ inputs.stage ]]
  variables:
   ... # removed for exaple
  tags: $[[ inputs.tags ]]

Using the compnent:

include:
  component: $COMPONENT_PATH
  inputs:
    tags: ["tag1", "tag2"]

We would like to be able to check the inputs.tags for the existence of “default_tag” and if it doesn’t exist modify it to be ["default_tag", "tag1", "tag2"]. Please let me know if you need more information.

Versions

  • Self-managed
  • GitLab.com SaaS
  • Dedicated
  • Self-hosted Runners

Hi,

I think your current goal is not possible with the current YAML-syntax.
You can’t check and do assignments afterward. So you would have to use a ci-job with a shell-script, but I think this is not what you want.

You might wanna use extends. (but it will not do completely what you want).
With extends you could always make sure that a default tag is added to the job (so you wouldn’t need to check it).

e.g.

.default_tag:
    tags:
        - my-default-tag

my-job:
    extends: .default_tag  # adds 'my-default-tag' to the job
    script:
        - echo "Hello World"
    tags:
        - job-tag1
        - job-tag2

As I said, its a different soluation what you asked for, but I think close enough.

Hey thanks for the reply. I actually went with a painfully obvious, but different solution. You are correct and it cannot be done with the YAML currently.

In the component you can simply set tags as follows:

build_docs:
  tags:
    - default_tag
    - $[[ inputs.tags ]]
2 Likes