2

I would like to create a gitlab variable using the variables: keyword that contains an array of dependencies to pass to the GitLab dependencies: keyword. The structure would look something like:

variables:
    DEPENDENCY_LIST: ["dependency1", "dependency2", "dependency3"]

dependencies: "$DEPENDENCY_LIST"

But the above code gives a YAML error saying that "jobs:source code dependencies should be an array of strings"

How can I set the value of a GitLab CI variable to an array in a .gitlab-ci.yml job?

1 Answer 1

5

How do you set a GitLab CI variable to an array in gitlab-ci?

You can't - environment variables are in the form name=value. There are no arrays.

Use yaml anchors.

.dependency_list: &dependency_list
   - dependency1
   - dependency2
   - dependency3

dependencies: *dependency_list

However gitlab-ci does not flatten nested arrays in dependencies, so there is no way to merge two arrays.

See gitlab ci documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.