Question
How do i call an external REST-API with oAuth2-Authentication from an Azure DevOps Pipeline?
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. Thus I tried to call the Bitbucket Cloud API manually from within the Pipeline to display the correct build-status in 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). 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.
- 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?

