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
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.