Search code examples
curlbitbucketcicd

Bitucket cloud - Curl payload request to trigger a pipeline


I want to send a curl request to trigger a pipeline in one of the repositories we managed, the curl command is this, based on the api reference docs https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#trigger-a-custom-pipeline-with-variables

curl -X POST -is -u "$BITBUCKET_USERNAME":"$BITBUCKET_APP_PASSWORD" \
--header 'Content-Type: application/json' \
https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/pipelines/ \
--data '
  {
    "target": {
      "ref_type": "branch",
      "type": "pipeline_ref_target",
      "ref_name": "develop",
      "selector": {
        "type": "custom",
        "pattern": "Deploy to environment"
      }
    },
    "variables": [
      {
        "key": "NAMESPACE",
        "value": "xxx"
      },
      {
        "key": "URL",
        "value": "https://api.xx.xxx.net/"
      },
      {
        "key": "KID",
        "value": "xxxxx"
      }
    ],
    "WAIT": true
 }'

But I got this error

{"error": {"message": "Bad request", "detail": "bitbucket-pipelines.yml not found.", 
"data": {"key": "result-service.pipeline.yml-not-found", "arguments": {}}}}

It is like the bitbucket-pipelines.yml wouldn't exist in the repository where I am trying to trigger the pipeline, but it does. Could be that apparently, the payload I am providing on the curl command is incorrect in somehow according to what the bitbucket cloud API expects?

How can I get this curl request properly formed?


Solution

  • Got it. At the selector attribute, in the pattern sub key I had to provide the name of the existing pipeline on the bitbucket-pipelines.yml file I want to be called to be executed on the request.

    I was doing this 

    "selector": {
       "type": "custom",
       "pattern": "Deploy to environment"
     }
    

     I need to do this

    "selector": {
         "type": "custom", 
         "pattern": "<pipeline-name-to-be-called>"
    }