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

How do I trigger a bitbucket pipeline using API request?

Ishan Roy August 19, 2021

I am trying to trigger a bitbucket pipeline using the api endpoint, but I am getting the following response: 
{
"error": {
"message": "Bad request",
"detail": "bitbucket-pipelines.yml not found.",
"data": {
"key": "result-service.pipeline.yml-not-found",
"arguments": {}
}
}
}

This is the request that I am using. I have verified and this branch has the pipeline and I am able to trigger it manually from pipelines section of the repo.

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": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "branchname"
},
"variables": [
{
"key": "key1",
"value": "value1"
},
{
"key": "key2",
"value": "value2"
}]
}'


1 answer

1 accepted

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 24, 2021

Hi @Ishan Roy and welcome to the community.

The data you need to send with the request depends on the type of the pipeline you want to trigger.

The documentation below has some examples:

Is the pipeline you want to trigger defined as follows

pipelines:
branches:
branchname:

in the bitbucket-pipelines.yml file of this branch? Or is it perhaps a custom pipeline? In case it's a custom pipeline, you'll need to include some additional fields in the request (you can check the examples in the doc).

We'd need to know in which section of your bitbucket-pipelines.yml file this pipeline is defined in order to figure out how it should get triggered.

Kind regards,
Theodora

Ishan Roy August 24, 2021

Hi @Theodora Boudale, It was a custom pipeline and I was able to trigger the same after adding the selector in the request body. Thanks for the support. 

{
"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "master",
"selector": {
"type": "custom",
"pattern": "Name"
}
}
}

Thanks and Regards,
Ishan Roy
Like Theodora Boudale likes this
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 25, 2021

Thank you for the update @Ishan Roy and you are very welcome, I'm glad to have helped!

Please feel free to reach out if you ever need anything else.

Kind regards,
Theodora

abhishek.singh April 18, 2022

@Theodora Boudale  it's not working because of  our repo under VPN  ,

abhishek.singh April 18, 2022

Api request working fine from local when we connected with vpn

But we want make request from bitbucket pipeline then it's not working
Because requester(bitbucket pipeline )have different ip not vpn ip
We are using bitbucket host

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events