0

在构建成功/失败后,我正在尝试将构建管道的状态发送到 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 构建管道中没有执行后门(类似于发布门),我还没有找到更好的方法来执行此操作。

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

谢谢,卡里

4

2 回答 2

0

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

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

这是一个有类似问题的案例,您可以参考。

于 2020-12-04T06:23:50.593 回答
0

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

于 2020-12-04T11:51:29.143 回答