5

I am trying to use 2 repositories on the same pipeline. One repository contains source code and the other has templates.

The azure-pipeline.yml of repository source code looks like this:


pool: alm-aws-pool 

resources: 
  repositories: 
  - repository: AzurePipelines 
    name: ALM/AzurePipelines 
    type: git 
    ref: master #branch name


steps:
- template: TG1_build&Nuget.yml@AzurePipelines
  parameters:
    solution: '**/*.sln'
    buildPlatform: 'Any CPU'
    buildConfiguration: 'Release'
    IsNugetPrerelaseVersion: true

The template TG1_build&Nuget.yml is:

steps:
- task: NuGetToolInstaller@1
  displayName: 'Use NuGet 5.1.0'
  inputs:
    versionSpec: 4.0.0
- task: NuGetCommand@2
  displayName: 'NuGet restore **/*.sln'
  inputs:
    vstsFeed: '****'
    noCache: true
- task: sonarqube@4
  displayName: 'Prepare analysis on SonarQube'
  inputs:
    SonarQube: 'SonarQube'
    projectKey: '$(Build.Repository.Name)'
    projectName: '$(Build.Repository.Name)'
- powershell: |
   #The double dollar is intended for using the constant $true or $false
   $isBeta=$$(IsNugetPrerelaseVersion) 
   if (-Not $isBeta) {
       exit 0;
   }
   
   $workingDirectory = "$(System.DefaultWorkingDirectory)"
   $filePattern = "*AssemblyInfo*"
   $pattern = '^(?!//)(?=\[assembly: AssemblyVersion\("(.*)"\)\])'
   
   Get-ChildItem -Path $workingDirectory -Recurse -Filter $filePattern | ForEach-Object {
       $path = $_.FullName
       Write-Host $path
       (Get-Content $path) | ForEach-Object{
           if($_ -match $pattern){
               # We have found the matching line
               # Edit the version number and put back.
               $fileVersion = $matches[1]
               $newVersion = "$fileVersion-beta"
               '[assembly: AssemblyVersion("{0}")]{1}[assembly: AssemblyInformationalVersion("{2}")]' -f $fileVersion,"`r`n",$newVersion 
           } else {
               # Output line as is
               $_
           }
       } | Set-Content $path
   }
   
   $filePattern = "**.csproj*"
   $pattern1 ="<Version>"
   $pattern2 ="</Version>"
   $pattern = '(?={0})' -f $pattern1
   $empty = ""
   
   Get-ChildItem -Path $workingDirectory -Recurse -Filter $filePattern | ForEach-Object {
       $path = $_.FullName
       Write-Host $path
       (Get-Content $path) | ForEach-Object{
           if($_ -match $pattern){
               # We have found the matching line
               # Edit the version number and put back.
               $fileVersion = $_
               $fileVersion = $fileVersion -replace $pattern1, $empty
               $fileVersion = $fileVersion -replace $pattern2, $empty
               $fileVersion = $fileVersion.Trim()
               $newVersion = "$fileVersion-beta"
               '<Version>{0}</Version>' -f $newVersion
           } else {
               # Output line as is
               $_
           }
       } | Set-Content $path
   }
  displayName: 'Update Assembly Info for nuget generation'
- task: VSBuild@1
  displayName: 'Build solution **\*.sln'
  inputs:
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(BuildConfiguration)-binaries.zip" /p:RunCodeAnalaysis=true'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    clean: true
    maximumCpuCount: true
    msbuildArchitecture: x64
    createLogFile: true
- task: NuGetCommand@2
  displayName: 'NuGet pack'
  inputs:
    command: pack
    packagesToPack: '$(SearchPatternToPack)'
    packDestination: '$(Build.ArtifactStagingDirectory)/nugets'
    includeReferencedProjects: true

When I try to ran this pipeline I found this error: /azure-pipelines.yml: File /TG1_build&Nuget.yml not found in repository https://dev.azure.com/Fabrikam/ALM/_git/AzurePipelines branch refs/heads/master version d6d59eef922dac0324654b49a71037a504102ff4

Someone can help us!

Thank you

Dàniel Hernández
  • 307
  • 1
  • 3
  • 14

4 Answers4

4

Ok, this is a dumb one but it cost me a few hours....

  1. Check whether the target file has yml vs yaml and ensure you are referencing the correct one!

This is a variation on the file actually existing, but I stared at this for a while before going "aha"

Paul Hatcher
  • 7,342
  • 1
  • 54
  • 51
2

You could try to use the checkout step to check out the source code from the other repository and make sure that the path is correct:

steps:
- checkout: AzurePipelines
  path: 's'
- template: s/TG1_build&Nuget.yml
...
mm8
  • 163,881
  • 10
  • 57
  • 88
1

I found I needed to prefix the template with /, or it was relative to the source pipeline template (which tipped me off to the real issue), rather than the root of the repository.

   - job: foo
     displayName: 'foo name'
     steps:
-      - template: azure-pipeline-templates/tests_integration.yml@self
+      - template: /azure-pipeline-templates/tests_integration.yml@self

The error:

/azure-pipelines/pipeline-tests-basic.yml: File /azure-pipelines/azure-pipeline-templates/tests_integration.yml not found in repository ..

The template exists in azure-pipeline-templates, which is at the same level as azure-pipelines

azure-pipelines
└ pipeline-tests-basic.yml
azure-pipeline-templates
└ tests_integration.yml

Presumably the difference occurs between pipelines which specify multiple repositories as a resource.

ti7
  • 16,375
  • 6
  • 40
  • 68
0

I created a testing yaml pipeline similar to yours above. I can only reproduce above error in below scenarios.

  • I ref to a wrong branch of the resource repository in which the template yaml file doesnot exist.

  • I type the name of template yaml file wrongly, which caused the template yaml file cannot be found.

So please checkout if the template yaml file exists in the master branch of the resource repository, and make sure the name template yaml file is correct.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • how does one "ref" to a branch? and how do I change this? – ZackOfAllTrades Dec 19 '22 at 19:18
  • @ZackOfAllTrades when you define a resource repository under `resources.repositories.repository`, you can change the targeted branch by adding a `ref:` property with the appropriate branch reference. – octagon_octopus Aug 30 '23 at 07:32