How to use InvokeRESTAPI@1 Azure DevOps Task, with waitForCompletion set to true?

119 Views Asked by At

I came across this Azure DevOps Task: InvokeRESTAPI@1

There is a property named 'waitForCompletion' which is designed to make an agentless job wait until it receives a callback from an external service before updating the timeline record.

Unfortunately, there are no examples in the Microsoft documentation, and I have not found any relevant wikis or articles on its usage.

Can you please provide an explanation or references?

1

There are 1 best solutions below

1
Kevin Lu-MSFT On BEST ANSWER

Based on this doc: InvokeRESTAPI@1 - Invoke REST API v1 task

Callback: reports completion when the external service makes a callback to update the timeline record.

When you set waitForCompletion to true(Callback), it will collect the completion signal sent by external services.

Therefore you need to add the following Post callback in the external service:

{planUri}/{projectId}/_apis/distributedtask/hubs/{hubName}/plans/{planId}/events?api-version=2.0-preview.1

Body:

{ "name": "TaskCompleted", "taskId": "taskInstanceId", "jobId": "jobId", "result": "succeeded" }

You can get the parameters valueof the URL in the Invoke Rest API task(e.g. planUri):

enter image description here

You need to receive the request in the external service and parse the headers to obtain the corresponding parameter values.

Finally, the Invoke Rest API will get the TaskCompleted signal and check if the task is successful or failed.

Here are the resources you can refer to:

Doc: Async Http Agentless Task

Repo Project Sample: HttpRequestSampleWithoutHandler

Blog: Controlling Azure DevOps Pipelines through Teams Integration and Manual Intervention Steps and HTTP requests in YAML based pipelines