My company has an Azure DevOps pipeline which publishes the development branch to cloudflare and prints a link to that deployment in the log.
I would like that link to appear in a PR comment so that the dev doesn't need to click through to the logs to find it.
How do I achieve this?
We can use this REST API Pull Request Thread Comments - Create in the pipeline.
Result:
First of all, make sure your build service has permissions to contribute to pull requests in your repository. Otherwise, you may get the error like this
There are two build service accounts
ProjectName Build Service (OrganizationName)
andProject Collection Build Service (OrganizationName)
. It depends on your pipeline configuration. The doc is here. If you are not sure which account you are using, you can search the idxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx
in the error message and you will see the account.If you are using the yaml pipeline, here is the sample. The first task is to set your link as variable
DeployURL
. Then we can use the variable in the following tasks.If you are using the classic build pipeline, please check the Allow scripts to access the OAuth token.
The Custom condition is set to only run the task when the build reason is pullrequest.