Problem to solve
I’m in the process of developing a GitLab component. The component has an input parameter of type string and I want to set it to a JSON String submitting a complex value to the component.
Unfortunately in all my tryouts the GitLab CI strips all double quotes of the JSON string making it unusable from inside the component.
Is there any way to let the JSON String untouched. So far I tried YAML variants of single line with single quotes, multi line with single quotes and unquoted JSON string.
Steps to reproduce
- Define a component with an input of type string.
- Use it in a GitLab pipeline with a JSON string as concrete parameter.
- Try to use it in the component.
Configuration
The relevant part of the CI Pipeline looks like this:
include:
- local: "/src/main/ci/templates/subst/subst.yaml"
inputs:
subst-context: '[ { "inputFile": "src/main/helm/feature/weblate/values.yaml", "outputFile": "target/helm/weblate/values.yaml" } ]'
target-path: target
The component looks like this:
# Substitutes placeholders in files with environment variables
spec:
inputs:
stage:
description: Optional stage of the job
type: string
default: subst
subst-context:
description: "An JSON array with input and output files to process"
type: array
target-path:
description: "The path where the substituted files are written to"
type: string
depends-on:
description: "Optional job dependencies"
type: array
default: []
---
subst-job:
stage: $[[ inputs.stage ]]
needs: $[[ inputs.depends-on ]]
script: |
# Check if input is a valid JSON array
echo "Received subst-context: $[[ inputs.subst-context ]]"
echo "$[[ inputs.subst-context ]]" | jq 'if (type != "array") then error("Input is not an array") end'
Versions
Please select whether options apply, and add the version information.
- Self-managed
-
GitLab.com
SaaS - Dedicated
- Self-hosted Runners
Versions
- GitLab v18.1.2 Community Editon
- GitLab Runner, self hosted