Search code examples
gitlabgitlab-cijirajira-rest-api

How to use a JIRA api POST curl in gitlab ci-cd having a body as json


script:
  - echo "Running unit tests... This will take about 60 seconds."
  - apk add curl
  - >
    curl -X POST "https://test.atlassian.net/rest/api/2/issue/" \
    -u "[email protected]:${JIRA_TOKEN}"
    -H "Accept: application/json" \
    -H "Content-Type: application/json" \
    -d '{
      "fields": {
        "project": {
          "key": "SNAP"
        },
        "summary": "Testing Gitlab Release",
        "description": "Issue Description",
        "issuetype": {
          "name": "Epic"
        }
      }
    }'
  - echo "Code coverage is 90%"

This is giving me an error in my curl request -> curl: (3) URL rejected: Malformed input to a URL function


Solution

  • Try this

    script: |
      echo "Running unit tests... This will take about 60 seconds."
      apk add curl
      curl -X POST "https://test.atlassian.net/rest/api/2/issue/"
        -u "[email protected]:${JIRA_TOKEN}"
        -H "Accept: application/json"
        -H "Content-Type: application/json"
        -d '{
          "fields": {
            "project": {
              "key": "SNAP"
            },
            "summary": "Testing Gitlab Release",
            "description": "Issue Description",
            "issuetype": {
              "name": "Epic"
            }
          }
        }'
      echo "Code coverage is 90%"