You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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".
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.