Invoke a function task

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

Use this task in an agentless job of a release pipeline to invoke an HTTP triggered function in a function app that is created and hosted in Azure Functions and parse the response.

Note

In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build 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
Function URL Required. The URL of the 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 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 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.

FAQ

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

To signal completion, the 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

Why does the task failed within 1 minute when the timeout is longer?

If the function executes for more than 1 minute, use the Callback completion event. The API Response completion option is supported for requests that complete within 60 seconds.