【问题标题】:Send the Build status of an Azure DevOps Server pipeline via REST to Bitbucket通过 REST 将 Azure DevOps 服务器管道的构建状态发送到 Bitbucket
【发布时间】:2021-03-15 15:11:19
【问题描述】:

我正在尝试在构建成功/失败后将构建管道的状态发送到 Bitbucket Server。 使用 Postman,我可以使用 REST API 成功更新提交的构建状态:

POST https://bitbucketserver/rest/build-status/1.0/commits/dac37f9ede70e9548528a1dd19409b352db624e6
204
177 ms
Warning: Self signed certificate in certificate chain
POST /rest/build-status/1.0/commits/dac37f9ede70e9548528a1dd19409b352db624e6 HTTP/1.1
Authorization: Basic eHhrbGk6MjlOb3ZlbWJlcjIwMjA=
Content-Type: application/json
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Postman-Token: e88d324b-e014-48e6-9a4c-5ad094e49aed
Host: nibcoderepo:7990
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 220
{
    "state": "SUCCESSFUL",
    "key": "Project",
    "name": "CI-Build",
    "url": "https://devops/Project/Repo/_build",
    "description": "Build status from Azure Devops Server"
}
HTTP/1.1 204 No Content

但是,当我尝试在管道中的无代理作业中运行 Invoke REST API 时,请求失败并且无法找到服务器。这是作业日志的输出:

============================================================================== 
Task         : Post build status
Description  : Invoke a REST API as a part of your pipeline.
Version      : 1.152.1
Author       : Microsoft Corporation
Help URL     : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/http-rest-api
============================================================================== 

                Parsing expression: <TaskInputs[TaskInputs['connectedServiceNameSelector']]>
                TaskInputs
                [
                ..TaskInputs
                ..[
                ....'connectedServiceNameSelector'
                ..]
                ]
                Evaluating: TaskInputs[TaskInputs['connectedServiceNameSelector']]
                Evaluating indexer:
                ..Evaluating TaskInputs:
                ..=> Object
                ..Evaluating indexer:
                ....Evaluating TaskInputs:
                ....=> Object
                ....Evaluating String:
                ....=> 'connectedServiceNameSelector'
                ..=> 'connectedServiceName'
                => '3f2eef60-1c18-4d2d-95ef-20b9946e6a16'
                Result: '3f2eef60-1c18-4d2d-95ef-20b9946e6a16'

POST https://bitbucketserver//rest/build-status/1.0/commits/b63a3c20f0b0df1fcaa163284f82e6efa9e84437
Request body: {
  "state": "SUCCESSFUL",
  "key": "Project",
  "name": "CI-Build",
  "url": "https://devops/Project/Repo/_build/results?buildId=822",
  "description": "Build status from Azure Devops Server"
}
                Response Code: 0
                Response: An error was encountered while processing request. Exception: <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>Oops, can&#39;t find that - Bitbucket</title><script>
....
Exception Message: The remote server returned an error: (404) Not Found. (type WebException)

我能够从 Azure DevOps 机器运行 Postman 请求,因此不存在防火墙问题。 有趣的是,我注意到 REST 调用的地址在机器地址之后有一个奇怪的 //,不知道这是否会导致问题...?

由于 Azure DevOps 构建管道中没有执行后门(类似于发布门),因此我还没有找到更好的方法。

还有其他人在这方面取得成功吗?

谢谢, 卡里

【问题讨论】:

    标签: rest azure-pipelines bitbucket-server azure-devops-server-2019 build-pipeline


    【解决方案1】:

    根据这个document,您可以尝试在您的管道中使用一个简单的脚本并使用构建 ID 进行更新。

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

    这里有一个case,你可以参考类似的问题。

    【讨论】:

    【解决方案2】:

    我最终解决了连接问题。 这样做的原因相当愚蠢,实际上与任务中 POST 请求 URL 的形成有关。删除第一个 / 字符有效,现在请求已成功发送到 Bitbucket 服务器。

    【讨论】:

    • 感谢您在这里分享您的解决方案,请您接受您的解决方案as the answer?因此,对于遇到相同问题的其他成员轻松找到解决方案将很有帮助。祝你有美好的一天:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    • 1970-01-01
    • 2020-11-26
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 2021-08-27
    相关资源
    最近更新 更多