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,721
Community Members
 
Community Events
177
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

Atlassian Community Events