Search code examples
gitlabyamlgitlab-ci

How can one define an array type variable in gitlab-ci


I'm writing a gitlab-ci.yaml script for my pipeline, and trying to define an array of strings variable (simplified version of the code):

npm_audit:
  variables:
    PACKAGE-WHITE-LIST: ["package A", "package B"]
  script:
   - npm install audit-ci
   - npx audit-ci -w PACKAGE-WHITE-LIST npm >> audit.log

When I run the pipeline, I get a yaml parse failure: "variables config should be a hash of key value pairs array"

What am I missing here?


Solution

  • Your code is not working for some reasons :

    • Your variable can't contain dash
    • You forgot the $ before your variable name to retrieve its value
    • You don't need to create an array

    The following definition should work :

      npm_audit:
      variables:
        PACKAGE_WHITE_LIST: "package A package B"
      script:
       - npm install audit-ci
       - npx audit-ci -w $PACKAGE_WHITE_LIST npm >> audit.log