ios - 如何从 Azure Pipeline 在 Bitbucket 中更新构建状态?

标签 ios azure-devops continuous-integration bitbucket azure-pipelines

我正在使用 Azure Pipeline 为 iOS 代码构建和运行测试。这些步骤工作正常。如何在 bitbucket 中显示构建状态?

我可以找到 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)

但是使用带有 print 'job name: {}'.format(os.getenv("BUILD_ID")) 的 python 任务运行它给我 None。如何让状态显示在 bitbucket 中?

最佳答案

Azure Pipeline 中用于构建 ID 的变量是 Build.BuildId,因此只需将 os.getenv("BUILD_ID") 替换为 os.getenv( “BUILD_BUILDID”)

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

结果:

enter image description here

可以看到here所有 Azure Pipelines 变量(检查您需要的其他变量)。

关于ios - 如何从 Azure Pipeline 在 Bitbucket 中更新构建状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56665060/

相关文章:

ios - 照片调整大小和压缩

ios - 在 Swift 中交换数组值

ios - 自定义 UIView 上的披露指示器

azure-devops - Azure DevOps wiki 在哪里存储评论?

Azure DevOps 可选阶段

docker - 如何设置liferay进行团队开发和部署?

ios - 我是否需要 iOS 通知服务扩展的分发配置文件?

c# - WACK 检查构建

msbuild - 在 MSbuild 构建期间获取项目版本信息

sql-server - 使用 Azure DevOps 部署数据库期间出现错误 "The DELETE statement conflicted with the REFERENCE constraint"