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?
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/"
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"
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"
Hope it helps and let me know if you have further questions.
Regards,
Mark C
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.