简体   繁体   中英

trigger 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?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM