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

How to trigger pipeline through API based on a tag?

Toms Seisums
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 24, 2018

I'm reading through the API docs and cannot find anything of much use: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pipelines/#post

To trigger a build on a branch, it's pretty simple:

# POST: /2.0/repositories/<account>/<repo>/pipelines
{
"target": {
"type": "pipeline_ref_target",
"ref_type": "branch",
"ref_name": "master"
}
}

And works as expected.

 

Then I attempted to trigger on tag. Docs mention:

The following reference types are supported:

  • branch

  • named_branch

  • bookmark

  • tag

So, my idea was that this should work:

# POST: /2.0/repositories/<account>/<repo>/pipelines
{
"target": {
"type": "pipeline_ref_target",
"ref_type": "tag",
"ref_name": "<tag_name>"
}
}

 But this resulted in:

{
"message": "retrofit2.adapter.rxjava.HttpException: HTTP 500 Internal Server Error (command RESULT_SERVICE_POST_PIPELINE, error key='Internal Server Error')",
"arguments": {
"spanId": df56828a4b0d7195,
"parentSpanId": "0000000000000000",
"traceId": "df56828a4b0d7195"
},
"key": "Internal Server Error"
}

 

How do I trigger pipeline through API for a specific tag?

2 answers

1 accepted

3 votes
Answer accepted
Linette
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 26, 2018

Hi there,

You are really close, but unlike a branch there can't be a HEAD of a tag, so the first example can only work for branches.

In order to trigger on a tag, you'll also have to specify the commit and hash, so it knows what to work from. If you format it in the style of the second example on the API page, it should work for you.

Toms Seisums
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 27, 2018

Thanks for the answer, got it to work!

# POST: /2.0/repositories/<account>/<repo>/pipelines

{
"target": {
"commit": {
"type": "commit",
"hash": "<tag_target_hash>"
},
"type": "pipeline_ref_target",
"ref_type": "tag",
"ref_name": "<tag_name>"
}
}

---

To feel it a little bit, I tried to pass an invalid commit hash, which resulted in quite a descriptive error:

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

So what I gather, is that it needs the commit hash, to find where the bitbucket-pipelines.yml is!

P.S. Reading through the docs again, that's exactly what it says, it has to find bitbucket-pipelines.yml file and it uses the commit hash for that.

---

Anyways, it would be great, if the initial request I made would also return a descriptive message.
The "Internal Server Error" does not help a single bit, especially, since one might think that actually something is messed up on your part and it really is a server error.

Linette
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 28, 2018

Wahoooooo!!! So glad you got it working!

Rakesh Sivagouni
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 25, 2019

what should we have to provide in type filed.

"type": "pipeline_ref_target"
Like Eric Miller likes this
0 votes
Martin Pätzold April 25, 2022

Hi there, I've tried to run a pipeline via the above mentioned solution, but I got errors and the pipeline won't run successfully.

Used URL: https://api.bitbucket.org/2.0/repositories/COMPANY/REPONAME/pipelines/

Used Body:

{
"target": {
"commit": {
"type": "commit",
"hash": "COMMIT_HASH"
},
"type": "pipeline_ref_target",
"ref_type": "tag",
"ref_name": "test-release-v0.0.1"
}
}

The pipeline will start, but stops with those errors:

warning: Could not find remote branch test-release-v0.0.1 to clone.
fatal: Remote branch test-release-v0.0.1 not found in upstream origin

@LinetteMay I ask you, if you have any idea to get this working? Or do you have a more detailed version of the documentation for this purpose?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events