How to get build status updated in Bitbucket from Azure Pipeline?

谁说我不能喝 提交于 2021-01-29 01:39:15

问题


I am using Azure Pipeline to build and run test for iOS code. Those steps works fine. How to display the build status in bitbucket?

I could find a script:

#!/usr/bin/env python

import os
import requests

# Use environment variables that your CI server provides to the key, name,
# and url parameters, as well as commit hash. (The values below are used by
# Jenkins.)
data = {
    'key': os.getenv('BUILD_ID'),
    'state': 'SUCCESSFUL',  # or 'FAILED' for a script that runs when the build fails
    'name': os.getenv('JOB_NAME'),
    'url': os.getenv('BUILD_URL'),
    'description': 'The build passed.'
}

# Construct the URL with the API endpoint where the commit status should be
# posted (provide the appropriate owner and slug for your repo).
api_url = ('https://api.bitbucket.org/2.0/repositories/'
           '%(owner)s/%(repo_slug)s/commit/%(revision)s/statuses/build'
           % {'owner': 'emmap1',
              'repo_slug': 'MyRepo',
              'revision': os.getenv('GIT_COMMIT')})

# Post the status to Bitbucket. (Include valid credentials here for basic auth.
# You could also use team name and API key.)
requests.post(api_url, auth=('auth_user', 'auth_password'), json=data)

But running it using python task with print 'job name: {}'.format(os.getenv("BUILD_ID")) is giving me None. How to get the status to show up in bitbucket?


回答1:


The variable in Azure Pipeline for build id is Build.BuildId, so just replace the os.getenv("BUILD_ID") to os.getenv("BUILD_BUILDID").

script: |
  import os
  id = os.getenv('BUILD_BUILDID')
  print(id)

Result:

You can see here the all Azure Pipelines variables (check there the another variables you need).



来源:https://stackoverflow.com/questions/56665060/how-to-get-build-status-updated-in-bitbucket-from-azure-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!