1

In my .gitlab-ci.yml file I want to send a notification to a WebexTeams or Spark room after each state. I can do this through a curl command (because webex teams or Spark use a REST API)

image:
  name: hashicorp/terraform:light
  entrypoint:
    - '/usr/bin/env'
    - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

before_script:
  - rm -rf .terraform
  - terraform --version
  - export AWS_ACCESS_KEY_ID
  - export AWS_SECRET_ACCESS_KEY
  - terraform init

.webexteams_variables: &webexteams_variables
  roomId = "Y2l***NGQy"

.webexteams_send: &webexteams_send
  script:  
  - curl --request POST --header 'Authorization: Bearer $bearer' --form 'roomId=$roomId' --form 'text=$msg' https://api.ciscospark.com/v1/messages 

stages:
  - validate

validate:
  stage: validate
  script:
    - terraform validate
  variables:
    msg: "Validation complete"
    <<: *webexteams_variables
  <<: *webexteams_send

I'm getting an issue

Status: syntax is incorrect Error: jobs:validate:script config should be an array of strings or a string

Removing the quotes is fixing this issue but then I get the following

Running with gitlab-runner 12.0.1 (0e5417a3) on gitlab-runner iRWmYNFc Using Docker executor with image hashicorp/terraform:light ... Pulling docker image hashicorp/terraform:light ... Using docker image sha256:0cd71852a450fe70bb72b7f8084b11d7b8ecd34027e0cb1521680aa426415737 for hashicorp/terraform:light ... Running on runner-iRWmYNFc-project-11-concurrent-0 via wauterw-gitlab-runner... /bin/bash: line 69: export: <<=roomId = "Y2l***Qy"': not a valid identifier /bin/bash: line 69: export:<<=roomId = "Y2l***Qy"': not a valid identifier ERROR: Job failed: exit code 1

Any idea how to fix this? If there are different ways to achieve this I would be interested to hear about them.

1 Answer 1

1

The yaml is invalid, there is something wrong with your anchor : you include webexteams_send containing a script: bloc but your validate job contains already a script: bloc.

If a correct that error, this .gitlab-ci.yml is valid :

image:
  name: hashicorp/terraform:light
  entrypoint:
    - '/usr/bin/env'
    - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

before_script:
  - rm -rf .terraform
  - terraform --version
  - export AWS_ACCESS_KEY_ID
  - export AWS_SECRET_ACCESS_KEY
  - terraform init

.webexteams_variables: &webexteams_variables
  roomId: "Y2l***NGQy"

stages:
  - validate

validate:
  stage: validate
  script:
    - terraform validate
    - 'curl --request POST --header "Authorization: Bearer $bearer" --form "roomId=$roomId" --form "text=$msg" https://api.ciscospark.com/v1/messages'
  variables:
    msg: "Validation complete"
    <<: *webexteams_variables

Note : the curl is between single quote because "the colon in the curl is interpreted as yaml's map key, because the whole shell command is not in quotes" see this related issue

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

1 Comment

Thanks a lot. The quotes were indeed mixed up. Works like a charm now.

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.