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?
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"
}]
}
"""
import urllib3
http = urllib3.PoolManager()
headers = urllib3.make_headers(basic_auth='{}:{}'.format(username, password))
resp = http.urlopen('POST', 'https://api.bitbucket.org/2.0/repositories/name/{34567890345678}/pipelines/', headers=headers, body=json.dumps(data))
print(str(resp.data))
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".
Remove the variables part. The "variables" part is to be used only with custom pipelines that have variables defined in the bitbucket-pipelines.yml file.
You don't need a selector either, since there is a definition for the branch main in your bitbucket-pipelines.yml file.
There's a running example here: https://betterprogramming.pub/trigger-bitbucket-pipeline-upon-s3-changes-6600ec5bd26b