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,294,584
Community Members
 
Community Events
165
Community Groups

Is it possible to trigger a Pipeline Deploy step via API?

I've got existing scripts to call pipelines via API to trigger the entire pipeline.

 curl -X POST -is -u user:pass \ -H 'Content-Type: application/json' \ https://api.bitbucket.org/2.0/repositories/myteam/${repo}/pipelines/ \ -d '{ "target": { "type": "pipeline_ref_target", "ref_type": "branch", "ref_name": "'$branch'", "selector": { "type": "branches", "pattern": "test-*" } } }'

Is it possible to actually call a API or a set of APIs to target the last completed pipeline for a given pattern and trigger the Deploy step only?

 

 

1 answer

0 votes
Mark C Atlassian Team Aug 18, 2021

Hi @Sidney Chen ,

Thank you for reach out to the community.

I'm afraid it is not possible to trigger a Pipelines build with the last completed Pipeline for a given pattern and only trigger the step inside that build.

As a workaround, you can trigger a Pipelines build via API using a custom step.

curl -u username:password -X POST -k -H 'Content-Type: application/json' -d '{"target": {"commit": {"hash":"COMMIT_HASH_HERE","type":"commit"},"selector": {"type": "custom","pattern": "CUSTOM_STEP_HERE"},"type": "pipeline_ref_target","ref_name": "SOME_BRANCH_HERE","ref_type": "branch"}}' "https://api.bitbucket.org/2.0/repositories/workspace_id/repo_name/pipelines/"

API Documentation

To check if the last commit in your branch succeeded a Pipelines build or not, you can use the API endpoints below.
However, please note that you'll have to parse the results until you get the build statuses for a commit
To get the last commit in a branch:

curl -u username:password "https://api.bitbucket.org/2.0/repositories/workspace_id/repo_name/commits/?include=SOME_BRANCH&fields=values.hash,values.links.statuses&size=1&pagelen=1"

API Documentation

To get the build statuses for a commit:

curl -u username:password "https://api.bitbucket.org/2.0/repositories/workspace_id/repo_name/commit/SOME_COMMIT_HAS/statuses?fields=values.name,values.state,values.refname"

API Documentation

Hope it helps and let me know if you have further questions.

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,158 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you