Search code examples
restazure-pipelinesbitbucket-serverazure-devops-server-2019build-pipeline

Send the Build status of an Azure DevOps Server pipeline via REST to Bitbucket


I'm trying to send the status of a build pipeline to Bitbucket Server after the build is successful/failed. With Postman, I'm able to successfully update the build status of a commit with the 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

However when I try to run the Invoke REST API in an agentless job in the pipeline, the request fails and is not able to find the server. Here's the output from the job log:

============================================================================== 
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://learn.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)

I'm able to run the Postman request from the Azure DevOps machine, so there is no firewall issue. Interestingly, I noticed that the address the REST call goes out to has a weird // after the machine address, don't know if that's something that could cause the issue...?

Since there is no post-execution gate in Azure DevOps build pipelines (similar to the release gates), I haven't figured out a better way to do this.

Has anyone else been successful in this?

Thanks, Karri


Solution

  • I was able to solve the connection issue in the end. The reason for this is rather stupid, and was in fact related to the formation of the POST request URL in the task. Removing the first /-character worked and now the request is successfully sent to Bitbucket Server.