Using With Repository Remote URL And Source Branch Name
This example shows how to write issues as comments to an Azure DevOps pull request while using repository information.
To determine the remote repository URL and source branch of the pull request you need the Cake.Git addin:
-
In production code this dependency should be pinned to a specific version to make sure builds are deterministic and won't break due to updates.
See Reproducible Builds for details.
To write issues as comments to Azure DevOps pull requests you need to import the core addin, the core pull request addin, the Azure DevOps support including the Cake.AzureDevOps addin, and one or more issue providers, in this example for JetBrains InspectCode:
#addin nuget:?package=Cake.Issues&version=5.0.1
#addin nuget:?package=Cake.Issues.InspectCode&version=5.0.1
#addin nuget:?package=Cake.Issues.PullRequests&version=5.0.1
#addin nuget:?package=Cake.Issues.PullRequests.AzureDevOps&version=5.0.1
#addin "Cake.AzureDevOps" // (1)!
-
In production code this dependency should be pinned to a specific version to make sure builds are deterministic and won't break due to updates.
See Reproducible Builds for details.
In the following task we'll first determine the remote repository URL and source branch of the pull request and with this information call the AzureDevOpsPullRequests alias, which will authenticate through NTLM to an on-premise Azure DevOps Server instance:
Task("ReportIssuesToPullRequest").Does(() =>
{
var repoRootFolder = MakeAbsolute(Directory("./"));
var currentBranch = GitBranchCurrent(repoRootFolder);
var repoRemoteUrl = new Uri(currentBranch.Remotes.Single(x => x.Name == "origin").Url);
var sourceBranchName = currentBranch.CanonicalName;
ReportIssuesToPullRequest(
InspectCodeIssuesFromFilePath(
@"C:\build\inspectcode.log"),
AzureDevOpsPullRequests(
repoRemoteUrl,
sourceBranchName,
AzureDevOpsAuthenticationNtlm()),
repoRootFolder);
});