通过 REST 将 Azure DevOps Server 管道的构建状态发送到 Bitbucket
Send the Build status of an Azure DevOps Server pipeline via REST to Bitbucket
我正在尝试在构建 successful/failed 之后将构建管道的状态发送到 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
但是,当我尝试 运行 在管道中的无代理作业中调用 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'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 构建管道中没有 post-执行门(类似于发布门),我还没有想出更好的方法。
还有其他人在这方面取得成功吗?
谢谢,
卡里
根据这个 document,您可以尝试在您的管道中使用一个简单的脚本并使用构建 ID 进行更新。
script: |
import os
id = os.getenv('BUILD_BUILDID')
print(id)
这里有一个类似的问题,你可以参考。
我最终解决了连接问题。
这个理由比较蠢,其实和任务中POST请求URL的形成有关。删除第一个 /- 字符有效,现在请求已成功发送到 Bitbucket 服务器。
我正在尝试在构建 successful/failed 之后将构建管道的状态发送到 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
但是,当我尝试 运行 在管道中的无代理作业中调用 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'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 构建管道中没有 post-执行门(类似于发布门),我还没有想出更好的方法。
还有其他人在这方面取得成功吗?
谢谢, 卡里
根据这个 document,您可以尝试在您的管道中使用一个简单的脚本并使用构建 ID 进行更新。
script: |
import os
id = os.getenv('BUILD_BUILDID')
print(id)
这里有一个
我最终解决了连接问题。 这个理由比较蠢,其实和任务中POST请求URL的形成有关。删除第一个 /- 字符有效,现在请求已成功发送到 Bitbucket 服务器。