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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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?

1 answer

1 accepted

2 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

Suggest an answer

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

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

1,217 views 0 3
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