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,467,284
Community Members
 
Community Events
177
Community Groups

How to trigger pipeline through API based on a tag?

Edited

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 Aug 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.

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 Aug 28, 2018

Wahoooooo!!! So glad you got it working!

what should we have to provide in type filed.

"type": "pipeline_ref_target"
Like Eric Miller likes this

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

Atlassian Community Events