pull-requestazure-pipelines-yamlazure-devops-services

Execute Yaml pipeline stored in different branch as PR build validation- Azure Devops Services


When trying to use build validation on Pull Request, I have added a pipeline (Tested and Working Manually) which is stored on different branch.

Then the Pull Request is started, I cannot see any advancement on Pipeline and the "Queue" button is grayed for several minutes and return to the same state. See image:

enter image description here

Pressing the "Queue" does not help as the pipeline did not start. Working on Azure DevOps Services with Git Repo on Azure Repos.

I have removed any limitations from the YAML (no trigger or branch restriction).

See YAML below

resources:
  repositories:
    - repository: self
      type: git
      name: GIT/aGit
      ref: refs/heads/dev/prbase
jobs:
- job: Phase_1
  displayName: Agent job 1
  timeoutInMinutes: 90
  pool:
    name: W10VS2022
  steps:
  - checkout: none
    fetchDepth: 1
    lfs: true
    persistCredentials: True
  - task: PowerShell@2
    name: Task1
    displayName: Stop All
    inputs:
      targetType: inline
      script: >-
        Write-Host "Stop all C:\install"

        Get-Process | Where-Object {$_.Path -like "c:\install*"} | Stop-Process -Verbose

** NO OPTION TO USE YAML IN DIFFRENT BRANCH FOR PR **


Solution

  • When trying to use build validation on Pull Request, I have added a pipeline which is stored on different branch.

    The cause of the issue is that the YAML file of pipeline is stored on different branch. I can reproduce the same issue when I do the same thing.

    If I change the pipeline to the one which the YAML file is stored on the source or target branch of the pull request, the pipeline will run as normal. Then, we can check the successful run and find that in the checkout step, it is Checkout reponame@refs/pull/{pullrequestID}/merge to s.

    So, the run triggered in build validation will use the source code of the pull request(@refs/pull/{pullrequestID}/merge). This make sense as the purpose of build validation is to check if the code in the pull request is good enough to merge.

    Back to your case, when the YAML file of pipeline is stored on different branch, this YAML file is not in the file list of the pull request. So, the pipeline will not run as YAML file doesn't exist.