[英]Calling Bitbucket 2.0 API from Azure DevOps Pipeline
Question题
How do i call an external REST-API with oAuth2-Authentication from an Azure DevOps Pipeline?如何从 Azure DevOps 管道调用带有 oAuth2-Authentication 的外部 REST-API?
What i am trying to achieve我正在努力实现的目标
So it seems that Azure Pipelines don't report the build-status properly back to Bitbucket, when multiple builds are triggered by the same commit.因此,当同一提交触发多个构建时,Azure Pipelines 似乎没有正确地将构建状态报告回 Bitbucket。 Thus I tried to call the Bitbucket Cloud API manually from within the Pipeline to display the correct build-status in Bitbucket.
因此,我尝试从流水线中手动调用 Bitbucket Cloud API 以在 Bitbucket 中显示正确的构建状态。
What i tried我试过的
The InvokeRESTAPI-Task looked promising, so i went ahead and created the required "generic" service connection (called "Bitbucket API" in the snippet below). InvokeRESTAPI-Task看起来很有希望,所以我继续创建所需的“通用”服务连接(在下面的代码段中称为“Bitbucket API”)。 However it seems that generic service connections only support basic auth flow?
但是,似乎通用服务连接仅支持基本身份验证流程?
The following taks sends a request to the correct URL, but fails with 401 - Unauthorized.以下任务向正确的 URL 发送请求,但失败并显示 401 - Unauthorized。
- task: InvokeRESTAPI@1
inputs:
connectionType: 'connectedServiceName'
serviceConnection: 'Bitbucket API'
method: 'POST'
body: |
{
"state": "INPROGRESS",
"key": "azure-pipeline",
"name": "CI-Pipeline 1",
"url": "tbd",
"description": "Lorem ipsum dolor sit amet"
}
urlSuffix: 'commit/$(Build.SourceVersion)/statuses/build'
waitForCompletion: 'false'
Is there an alternative that i missed or am i actually required to implement the oAuth-flow myself in python or powershell?有没有我错过的替代方案,或者我实际上需要在 python 或 powershell 中自己实现 oAuth-flow?
Instead of using OAuth , you could also consider using App passwords .除了使用OAuth 之外,您还可以考虑使用App 密码。
Then you can use simple bash task to call the API via curl command:然后你可以使用简单的bash 任务通过 curl 命令调用 API:
curl -X POST -is -u <USER_NAME>:<APP_PASSWORD> \
-H 'Content-Type: application/json' \
https://api.bitbucket.org/2.0/repositories/<USER_NAME>/<REPOSITORY_SLUG>/commit/<COMMIT>/statuses/build \
-d '{
"state": "SUCCESSFUL",
"name": "Build key - description",
"url": "https://<AZURE_URL_REFERENCE>",
"description": "A general description"
}'
For more details you can check this similar issue .有关更多详细信息,您可以查看此类似问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.