Ошибка Azure Pipeline: файл шаблона не найден в репозитории

Я пытаюсь использовать 2 репозитория в одном конвейере. Один репозиторий содержит исходный код, а другой - шаблоны.

Исходный код репозитория azure-pipeline.yml выглядит так:


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

Шаблон TG1_build & Nuget.yml:

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

Когда я пытаюсь запустить этот конвейер, я обнаружил следующую ошибку: /azure-pipelines.yml: Файл /TG1_build&Nuget.yml не найден в репозитории https://dev.azure.com/Fabrikam/ALM/_git/AzurePipelines. ветка refs / Heads / основная версия d6d59eef922dac0324654b49a71037a504102ff4

Кто-нибудь может нам помочь!

Спасибо


person Dàniel Hernández    schedule 30.06.2020    source источник


Ответы (3)


Вы можете попробовать использовать checkout, чтобы проверить исходный код из другого репозитория и убедиться, что путь правильный:

steps:
- checkout: AzurePipelines
  path: 's'
- template: s/TG1_build&Nuget.yml
...
person mm8    schedule 30.06.2020

Я создал тестовый конвейер yaml, похожий на ваш выше. Я могу воспроизвести указанную выше ошибку только в следующих сценариях.

  • Я ссылаюсь на неправильную ветку репозитория ресурсов, в которой не существует файла yaml шаблона.

  • Я неправильно ввожу имя файла шаблона yaml, из-за чего файл yaml шаблона не может быть найден.

Поэтому проверьте, существует ли файл yaml шаблона в главной ветви репозитория ресурсов, и убедитесь, что файл yaml шаблона имени правильный.

person Levi Lu-MSFT    schedule 01.07.2020

Я обнаружил, что мне нужно добавить к шаблону префикс /, или он относился к шаблону исходного конвейера (который подсказал мне реальную проблему), а не к корню репозитория.

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

Ошибка:

/azure-pipelines/pipeline-tests-basic.yml: файл /azure-pipelines/azure-pipeline-templates/tests_integration.yml не найден в репозитории ..

Шаблон существует в azure-pipeline-templates, который находится на том же уровне, что и azure-pipelines.

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

Предположительно разница возникает между конвейерами, которые определяют несколько репозиториев в качестве ресурса.

person ti7    schedule 21.08.2020