shivam aima
shivam aima

Reputation: 113

How to solve gitlab yaml script invalid syntax error

I have a script which for some reason is invalid with a bunch of errors generated in gitlab pipeline and ci lint such as:

  1. Syntax is incorrect

  2. (): did not find expected key while parsing a block mapping

  3. bad indentation of a sequence entry

    .publish:
      image: python:3
      script:
        - printf "const config = { apiUrl: '${API_URL}', environment: 
         '${CI_ENVIRONMENT_SLUG}', userpool_client_id: '${USERPOOL_CLIENT_ID}', 
          cognito_domain: '${COGNITO_DOMAIN}' }" > ${BUILD_DIR}/config.js
    

It creates an object called config and prints it into config.js file during buildtime.

Upvotes: 1

Views: 1045

Answers (1)

danielnelz
danielnelz

Reputation: 5136

You need to format your script as a multiline block. One such option would be to use a literal scalar (|) to preserve your new lines.

.publish:
  image: python:3
  script:
    - |
      printf "const config = { 
        apiUrl: '${API_URL}', 
        environment:'${CI_ENVIRONMENT_SLUG}', 
        userpool_client_id: '${USERPOOL_CLIENT_ID}', 
        cognito_domain: '${COGNITO_DOMAIN}' 
      }" > ${BUILD_DIR}/config.js

Upvotes: 1

Related Questions