Is there any Bitbucket Pipeline API available?

Joao Monteiro October 20, 2016

Helllo guys,

We have several integrations with Bitbucket API and we would like to use Pipelines to automate some tasks.

In order to do that, we need a Pipeline API that should:

  • Create a new pipeline for a repo with a specific image
  • Configure new branches in a pipeline
  • Configure scripts for each step
  • Start pipeline execution

Do you have plans for that?

 

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 8, 2017

Hello,

Just to follow up, the REST API has been released.

Information can be found here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pipelines

Thanks,

Phil

PravinU February 8, 2018

I want to enable the pipeline using rest api, any thoughts how we can achieve itV

Like Sarah Dwyer likes this
Jeroen De Raedt
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 15, 2018

Hi @PravinU, unfortunately we currently don't have a public REST endpoint available to achieve this. What exactly is your use case for this?

Louis Willcock May 6, 2018

@Jeroen De RaedtI'm trying to create an automated process which takes some inputs and changes bitbucket pipeline envvars as a result, it's a CI type solution, can I do this from outside the application? Say in a shell script?

Jeroen De Raedt
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 6, 2018

Hi @Louis Willcock,

there are REST endpoints available to create variables: 

Obviously you can invoke these endpoints as part of a shell script or something. 

Louis Willcock May 6, 2018

@Jeroen De RaedtCheers for the links, one thing that has been baffling me is being able to actually access the API's, for example authing and whatnot, I dunno if I'm just being a noob but I can't wrap my head around how to actually get anything back off them.

Jeroen De Raedt
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 6, 2018

What exactly is your use case?

If you are setting up some kind of automation, I recommend using an App password: https://developer.atlassian.com/bitbucket/api/2/reference/meta/authentication#app-pw

Louis Willcock May 7, 2018

@Jeroen De RaedtGot my main issue sorted now, however another question for you would be whether I can force updates on POST for config variables when they already exist, or whether I have to use the PUT api instead? I have noticed there is an answer to a very similar question underneath this one, but I guess I'm wondering if there's a cleaner solution.

Jeroen De Raedt
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 7, 2018

Yep, use PUT: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pipelines_config/variables/%7Bvariable_uuid%7D#put

Alternatively you could do a DELETE and then a POST but that's a bit more cumbersome. 

Out of curiosity, what are you trying to accomplish?

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 25, 2019

@Ward Loos Good catch! I've opened an internal ticket to get that looked into. You can follow the public ticket here: https://bitbucket.org/site/master/issues/18981/pipelines-and-pipelines_config-rest-api

1 vote
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 20, 2016

Hello Joao,

We've almost completed work for the Bitbucket Pipelines REST API. The API, and all its core functionality is done. It is still currently undocumented and there are possibly some small modifications to be made. But, you can try out the API now!

Our UI makes use of the API (have a look at the Logs Page, Pipelines Page, and Pipelines Settings pages), so you can look at the network traffic to determine the usage. 

You can watch this issue to get notified when we complete the remaining work (and officially release the API). https://bitbucket.org/site/master/issues/13116/add-pipelines-endpoint-to-rest-api

As a world of warning, since we haven't officially released it yet. Consider the API to still be volatile to changes. smile But try it out, and know that it's on the way!

Thanks,

Phil

0 votes
Alexander Shulgin March 1, 2018

Sometimes when i am calling

curl -X GET -s -u usr:pwd -H 'Content-Type: application/json' https://api.bitbucket.org/2.0/repositories/<owner>/<repo>/pipelines/<uuid>/steps/

i am getting error

{"error": {"message": "Bad request", "data": {"arguments": {}, "key": "rest-service.rest-service.invalid-state"}, "detail": "Invalid state provided 'READY'"}}

but the next call to the same url is responding with OK and expected data.

that happens , probably,  because i am trying to get steps of a pipeline that is in running state.

Any ways to fix that?

Jeroen De Raedt
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 6, 2018

Hi @Alexander Shulgin,

this is indeed a weird error. Is still happening now, or has it been resolved? 

0 votes
Vjatseslav Rosin February 15, 2017

Hello there!

I have checked out the API available for Bitbucket Pipelines, but haven't found there a way to change environment variables using the API. Are these methods available? 

Basically I would like to implement a hack to update env vars every 12 hours with new username and password information to be able to get my private docker images from AWS ECR service.

See question 39136149 for more details about this hack.

Slava

Artem Demchishin March 17, 2017

Hi Slava,

 

I've did something like this. All commands bellow are part of pipeline script.

# Get current release version from Pipelines environment variable
- export RELEASE_VERSION=`curl -s -X GET --user "$BB_AUTH_TOKEN" "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/pipelines_config/variables/" | sed 's/"{//g' | sed 's/}"//g' | sed 's/[{]/{\'$'\n/g' | sed 's/[}]/\'$'\n}/g' | awk "/RELEASE_VERSION/ {print $1}" | sed 's/"//g' | sed 's/value:\ //g' | awk -F', ' '{print $1}'`
- export RELEASE_VAR_UUID=`curl -s -X GET --user "$BB_AUTH_TOKEN" "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/pipelines_config/variables/" | sed 's/"{//g' | sed 's/}"//g' | sed 's/[{]/{\'$'\n/g' | sed 's/[}]/\'$'\n}/g' | awk "/RELEASE_VERSION/ {print $1}" | sed 's/"//g' | sed 's/uuid:\ //g' | awk -F', ' '{print $4}'`
            
# Increment release version and update Piplines environment variable RELEASE_VERSION to increased value
- export RELEASE_VERSION="${RELEASE_VERSION%.*}.$((${RELEASE_VERSION##*.}+1))"
- curl -s -X PUT curl -H 'Content-Type:application/json' --user "$BB_AUTH_TOKEN" -d '{"value":"'"$RELEASE_VERSION"'"}' "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/pipelines_config/variables/%7B$RELEASE_VAR_UUID%7D"

 

Hope it will useful for you.

 

Cheers,

Artem

Artem Demchishin March 17, 2017

PS: BB_AUTH_TOKEN is a pipeline variables "username:{APP_PASSWORD}", BITBUCKET_REPO_OWNER & BITBUCKET_REPO_SLUG - are available in pipeline container OOTB.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events