Unable to use input arrays type in Gitlab CI Component

Problem to solve

Describe your question in as much detail as possible:

Hello Folks,
I am trying to use the array type recently introduced in the GitLab Component. I am a bit blocked with the syntax. Below is a glimpse of the existing template that I used. I am not able to fetch the value out of the inputs for some reason.

Configuration

spec:
  inputs:    
    container_image_tag:
      type: array
      default:
        - ${CI_COMMIT_SHA}
        - latest
      description: "Container Image Tags"

build-container-image:
  stage: build
  image: alpine:latest
  script: |
    tags=$[[ inputs.container_image_tag ]]
    for tag in "${tags[@]}"    
    do
      echo $tag
    done

Output
/busybox/sh: eval: line 186: latest]: not found25


Versions

  • Self-managed
  • 17.0.x instance and runner as well

Its about how sh handles arrays, not gitlab
you have to do smth like this

  - TAGS=$(echo '$[[ inputs.container_image_tag ]]' | tr -d '[],"')
  - set -- $TAGS
  - for tag in "$@"; do echo "do smth with $tag"; done

your approach is right if you used bash, except for assigning a var. You need to make a separated string(cut brackets etc)
other options:

  1. jq or sed instead tr(but you will probably have to deal with resolving/substituting $CI_COMMIT_SHA inside array).
  2. Install bash or run it on image with bash preinstalled
2 Likes