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,293,533
Community Members
 
Community Events
165
Community Groups

run bitbucket pipeline with python

I am trying to run my bitbucket pipeline ```branches/main``` with this script. Currently, when I run it, I see no output. No error/success message. When I check on bitbucket, the pipeline has not run. How can I further debug this?
```
import requests
headers = {
'Content-type': 'application/json',
}

data = """
{"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "main",
"selector": {
"type": "branches",
"pattern" : "main"
}
},
"variables": [
{
"key" : "build_number",
"value" : "3"
},
{
"key" : "workspace",
"value" : "My Name"
}]
}
"""

response = requests.post('https://api.bitbucket.org/2.0/repositories/workspaceidmyname/{f567890098765456789234560}/pipelines/', headers=headers, data=data, auth=(username, password))
print(response.text)
```

Am I using the wrong selector or name? This is how my ```bitbucket-pipelines.yml```file looks like:
```
image: atlassian/default-image:3

pipelines:
default:
- step:
name: 'default'
script:
- echo "Your security scan goes here..."
branches:
main:
- step:
name: 'Validate'
script:
- echo "main branch's pipeline"
```

For the authentication, I used an "app password".

1 answer

0 votes

Hi @Azmah Aaban,

You don't need to use a selector, since there is a definition for the branch main in your bitbucket-pipelines.yml file. If you run this call with target main, the pipeline for the main branch will run.

The "variables" part in the data is to be used only with custom pipelines that have variables defined in the bitbucket-pipelines.yml file.

Can you try running the call with the following data?

{
"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "main"
}
}

I'm not very familiar with Python so I'm not sure if the rest of the details are correct, but an example with curl which should work is the following:


curl -X POST -is -u BitbucketUsername:AppPassword \
-H 'Content-Type: application/json' \
https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/pipelines/ \
-d '
{
"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "main"
}
}'

The values in bold are the ones that need to be replaced with the respective ones for your account, workspace, and repo.

Kind regards,
Theodora

Suggest an answer

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

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,096 views 2 9
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