curlgitlabjobs

Using curl with Gitlab job gives invalid yaml error


So I have the following curl command to hit an Endpoint, but get a :script config should be a string or a nested array of strings up to 10 levels deep error.

This is my curl command:

 script:
    - curl -X GET --header 'Accept: application/json' 'https://main-demo-services.nr.dflop-swf-prod.bee.ds.local/services/dataUser/namebreak/recache/status/'

Solution

  • I had this issue today. This is due to the colon (:) in the curl command being evaluated as a key-value pair.

    There are a few fixes for this. The cleanest one I found was to wrap the curl command in a single apostrophe ('):

    script:
        - 'curl -X GET --header 'Accept: application/json' 'https://main-demo-services.nr.dflop-swf-prod.bee.ds.local/services/dataUser/namebreak/recache/status/''
    

    Another solution is to abstract the curl command utilising eval:

    variables:
        CURL_COMMAND: `curl -X GET --header 'Accept: application/json' 'https://main-demo-services.nr.dflop-swf-prod.bee.ds.local/services/dataUser/namebreak/recache/status/'`
    script:
        - eval $CURL_COMMAND