Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,415,125
Community Members
 
Community Events
170
Community Groups

Trigger Custom Pipeline using API

Hi All,

I'm trying to trigger a custom pipeline for a particular branch using the following API call below:

curl -X POST -is -u <user>:<password> \

-H 'Content-Type: application/json' \

https://api.bitbucket.org/2.0/repositories/<account>/<repo>/pipelines/ \

-d ' { "target": { "ref_type": "branch", "type": "pipeline_ref_target", "ref_name": "<branch_name>" } }'

My yaml file has two paths, one is custom and the other is branch name based. The branch name based path works without issue however I'm unable to trigger the custom pipeline path without having to go the UI and doing it manually there ( I have a few repos so I don't want to constantly go back to the UI through each repo to trigger the custom path, rather script it up in a loop to fire them all off)

It ends up giving this response after posting

"Bad request", "detail": "bitbucket-pipelines.yml not found."

If I check the branch <branch_name> for that repo I can see that the bitbucket-pipelines.yml file is definitely there. Am I missing something obvious here? It makes me think the API is hitting some other branch where the file does not exist, but all branches in that repo has a bitbucket-pipelines.yml file.

1 answer

1 accepted

1 vote
Answer accepted
Raul Gomis Atlassian Team May 23, 2019

Hey @Sidney Chen ,

How exactly are you triggering the custom pipeline? I'd suggest that you try this example, adding the selector field to specify the custom pipeline you want to run:

curl -X POST -is -u username:password \
  -H 'Content-Type: application/json' \
 https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pipelines/ \
 -d '
  {
    "target": {
      "type": "pipeline_ref_target",
      "ref_type": "branch",
      "ref_name": "master",
      "selector": {
        "type": "custom",
        "pattern": "my-custom-pipeline-name"
      }
    }
  }'

More details and examples in here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pipelines/

Perfect! just what I was looking for @Raul Gomis . I kept having to trigger it from the UI since I didn't realise thats how the selector field worked.

Thanks!

@Raul Gomis  - Is there a way I can pass multiple values in pattern, or what is the correct way to achieve below use-case. 

"pattern": "my-custom-pipeline-name"

I have a use case to execute all custom steps in the below YAML file one after the other from custom bitbucket pipeline API ? 

pipelines:

  custom:

    create-aws-account:

      - variables:

          - name: account_id # single string (required)

      - step: *tfapply

    set-sso-permissions:

      - variables:

          - name: aws_account_id # single string (required)

          - name: aws_region # us-east-1 or ca-central-1

      - step: *aws_sso_access

    run-cloudhealth-pipeline:

      - variables:

          - name: aws_account_name

          - name: aws_account_id

      - step: *cloudhealth_pipeline

    run-tekton-pipeline:

      - variables:

          - name: account_id # single string (required)

          - name: app_id # single string (optional)

      - step: *tekton_pipeline
Raul Gomis Atlassian Team Jul 12, 2021

@Ranopriyo Neogy You can trigger two separate requests. I would recommend to use the following trigger-pipeline pipe to simplify the process and make it more user friendly with no code required. There is a good example in this Community post: https://community.atlassian.com/t5/Bitbucket-Pipelines-questions/I-m-using-atlassian-trigger-pipeline-can-I-request-WAIT-but-not/qaq-p/1633748.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events