A set of Azure DevOps Triggers and Bindings for Azure Functions. Leverages Azure Functions platform to simplify integration, automation, import/export and data synchronization scenarios for Azure DevOps.
As a prerequisite, you will need Azure Functions Core Tools installed on your devbox.
1. Create a local folder, name it e.g. AzFunc4DevOpsTest
and initialize an Azure Functions .NET project in it:
func init --worker-runtime dotnet
2. Install AzFunc4DevOps.AzureDevOps NuGet package:
dotnet add package AzFunc4DevOps.AzureDevOps
code .
Alternatively open the project in Visual Studio or any other IDE of your choice.
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobsStorage": "my-azure-storage-connection-string",
"AZFUNC4DEVOPS_AZURE_DEVOPS_ORG_URL": "https://dev.azure.com/my-company-name",
"AZFUNC4DEVOPS_AZURE_DEVOPS_PAT": "my-azure-devops-personal-access-token"
}
}
AzureWebJobsStorage
needs to be configured, because AzFunc4DevOps internally uses Azure Durable Functions, which require a storage. It's OK to use Azurite for local development.
AZFUNC4DEVOPS_AZURE_DEVOPS_ORG_URL
is your Azure DevOps organization's full URL. E.g. https://dev.azure.com/my-company-name
.
AZFUNC4DEVOPS_AZURE_DEVOPS_PAT
is your Azure DevOps Personal Access Token. Create one in Azure DevOps portal. Alternatively use KeeShepherd tool for creating and safely handling it.
NOTE: the PAT needs to be given all relevant scopes. E.g. if your Function is going to read/write Work Items, then vso.work_write
will be needed.
As an alternative to AZFUNC4DEVOPS_AZURE_DEVOPS_ORG_URL
and AZFUNC4DEVOPS_AZURE_DEVOPS_PAT
settings you can specify OrgUrl
and PersonalAccessToken
properties in every trigger/binding attribute. Those properties (just like any other trigger/binding attribute property) also support %MY-SETTING-NAME%
syntax. See the example here.
E.g. the following Function adds [Critical]
title prefix to a bug, once its Severity
field changes to 1 - Critical
:
public static class AddCriticalToBugTitle
{
[FunctionName(nameof(AddCriticalToBugTitle))]
[return: WorkItem(Project = "MyProjectName")]
public static WorkItemProxy Run
(
[WorkItemChangedTrigger
(
Project = "MyProjectName",
WiqlQueryWhereClause = "[System.WorkItemType] = 'Bug'",
FieldName = "Microsoft.VSTS.Common.Severity",
ToValue = "1 - Critical"
)]
WorkItemChange change
)
{
var item = change.NewVersion;
if (!item.Title.StartsWith("[Critical]"))
{
item.Title = "[Critical] " + item.Title;
}
return item;
}
}
func start
You can find more sample Functions in the samples folder.
See the documentation in our Wiki.
Also see this introductory blog post about AzFunc4DevOps here.
Is very much welcomed.