Skip to content

AzurePipelinesPullRequestInfo fails to detect if build is running in the context of a GitHub Pull Request #4410

@ap0llo

Description

@ap0llo

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

Cake runner

Cake Frosting

Cake version

5.0.0

Operating system

Windows

Operating system architecture

x64

CI Server

Azure DevOps

What are you seeing?

When running a build for a GitHub Pull Request on Azure Pipelines, AzurePipelinesPullRequestInfo.Id returns 0 and AzurePipelinesPullRequestInfo.IsPullRequest returns false even though the corresponding environment variables are set by Azure Pipelines

Analysis

I think I already found the root cause for the issue:

  • The Pull Request Id is stored as int but the Ids on github,com exceeded int.MaxValue some time ago (for example, in one recent PR I opened, the id was 2246475303)
  • The fix would be to use long instead, but I guess this would be a breaking change

Workaround

As a workaround for detecting if a build is a PR build, check if AzurePipelinesPullRequestInfo.Number is greater than 0.
This will return the Pull Request number as shown in the GitHub UI, which should fir well within a int

What is expected?

  • AzurePipelinesPullRequestInfo.IsPullRequest should return true
  • AzurePipelinesPullRequestInfo.Id should return the id of the pull request (this is different from the PR number)

Steps to Reproduce

Example of a Cake.Frosting-based build that runs into this can be seen here

  • Set up a Cake.Frosting-based build in a GitHub-hosted repository
  • Set up a pipeline on Azure Pipelines
  • In the build, access context.AzurePipelines().Environment.PullRequest.Id or context.AzurePipelines().Environment.PullRequest.IsPullRequest

Output log

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions