Using With Azure Pipelines

To write issues as comments to Azure DevOps pull requests, the Azure DevOps addin needs to be imported. For this example the JetBrains InspectCode issue provider is additionally used for reading issues:

build.cake
#addin nuget:?package=Cake.Issues&version=5.2.0
#addin nuget:?package=Cake.Issues.InspectCode&version=5.2.0
#addin nuget:?package=Cake.Issues.PullRequests&version=5.2.0
#addin nuget:?package=Cake.Issues.PullRequests.AzureDevOps&version=5.2.0
#addin nuget:?package=Cake.AzureDevOps&version=5.0.0

Note

In addition to the Azure DevOps pull request system the Cake.Issues and Cake.Issues.PullRequests core addins and the Cake.AzureDevOps addin need to be added.

Build.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Cake.Frosting" Version="5.0.0" />
    <PackageReference Include="Cake.Frosting.Issues.InspectCode" Version="5.2.0" />
    <PackageReference Include="Cake.Frosting.Issues.PullRequests.AzureDevOps" Version="5.2.0" />
  </ItemGroup>
</Project>

The following example shows a task which will call the AzureDevOpsPullRequests alias to connect to the pull request using the environment variables provided by Azure Pipelines.:

build.cake
Task("Report-IssuesToPullRequest").Does(() =>
{
    var repoRootFolder =
        MakeAbsolute(Directory("./"));

    ReportIssuesToPullRequest(
        InspectCodeIssuesFromFilePath(
            @"C:\build\inspectcode.log"),
        AzureDevOpsPullRequests(),
        repoRootPath);
});
Program.cs
using Cake.Common.IO;
using Cake.Frosting;

public static class Program
{
    public static int Main(string[] args)
    {
        return new CakeHost()
            .Run(args);
    }
}

[TaskName("Report-IssuesToPullRequest")]
public sealed class ReportIssuesToPullRequestTask : FrostingTask<FrostingContext>
{
    public override void Run(FrostingContext context)
    {
        var repoRootPath =
            context.MakeAbsolute(context.Directory("./"));

        context.ReportIssuesToPullRequest(
            context.InspectCodeIssuesFromFilePath(
                @"C:\build\inspectcode.log"),
            context.AzureDevOpsPullRequests(),
            repoRootPath);
    }
}

Info

Please note that you'll need to setup your Azure Pipelines build to Allow scripts to access the OAuth token and need to setup proper permissions.

See OAuth authentication from Azure Pipelines for details.