Invoke Azure Function task

Azure Pipelines | Azure DevOps Server 2019 | TFS 2018 | TFS 2017

Use this task in a build or release pipeline to invoke a HTTP triggered function in an Azure function app and parse the response.

Note

In Microsoft Team Foundation Server (TFS) 2018 and previous versions, run and release pipelines are called definitions, runs are called builds, service connections are called service endpoints, stages are called environments, and jobs are called phases.

Demands

Can be used in only an agentless job of a release pipeline.

YAML snippet

# Invoke Azure Function
# Invoke an Azure Function
- task: AzureFunction@1
  inputs:
    function: 
    key: 
    #method: 'POST' # Options: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, PATCH
    #headers: '{Content-Type:application/json, PlanUrl: $(system.CollectionUri), ProjectId: $(system.TeamProjectId), HubName: $(system.HostType), PlanId: $(system.PlanId), JobId: $(system.JobId), TimelineId: $(system.TimelineId), TaskInstanceId: $(system.TaskInstanceId), AuthToken: $(system.AccessToken)}' 
    #queryParameters: # Optional
    #body: # Required when method != GET && Method != HEAD
    #waitForCompletion: 'false' # Options: true, false
    #successCriteria: # Optional

Arguments

Parameter Comments
Azure function URL Required. The URL of the Azure function to be invoked.
Function key Required. The value of the available function or the host key for the function to be invoked. Should be secured by using a hidden variable.
Method Required. The HTTP method with which the function will be invoked.
Headers Optional. The header in JSON format to be attached to the request sent to the function.
Query parameters Optional. Query parameters to append to the function URL. Must not start with "?" or "&".
Body Optional. The request body for the Azure function call in JSON format.
Completion Event Required. How the task reports completion. Can be API response (the default) - completion is when function returns success and success criteria evaluates to true, or Callback - the Azure function makes a callback to update the timeline record.
Success criteria Optional. How to parse the response body for success.
Control options See Control options

Succeeds if the function returns success and the response body parsing is successful, or when the function updates the timeline record with success.

For more information about using this task, see Approvals and gates overview.

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q&A

Where should a task signal completion when Callback is chosen as the completion event?

To signal completion, the Azure function should POST completion data to the following pipelines REST endpoint.

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

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

See this simple cmdline application for specifics. In addition, a C# helper library is available to enable live logging and managing task status for agentless tasks. Learn more