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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Wahoooooo!!! So glad you got it working!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what should we have to provide in type filed.
"type": "pipeline_ref_target"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.