我正在尝试在同一管道上使用2个存储库。一个存储库包含源代码,另一个存储库包含模板。
存储库源代码的azure-pipeline.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
模板TG1_build&Nuget.yml为:
JSON.stringify(entry)
.replace(/\,/g, " ") // replace comma's with spaces
.replace(/\s+/g, " ").trim() //remove extra spaces with only one and trim
.replace(/[\{\}]/g, "") //To replace multiple
当我尝试运行此管道时,发现此错误: /azure-pipelines.yml:在存储库https://dev.azure.com/Fabrikam/ALM/_git/Vueling.AzurePipelines分支refs / heads / master版本d6d59eef922dac0324654b49a71037a504102ff4中找不到文件/TG1_build&Nuget.yml
有人可以帮助我们!
谢谢
答案 0 :(得分:0)
您可以尝试使用checkout步骤从另一个存储库中签出源代码,并确保路径正确:
steps:
- checkout: AzurePipelines
path: 's'
- template: s/TG1_build&Nuget.yml
...
答案 1 :(得分:0)
我创建了一个类似于您上面的测试yaml管道。我只能在以下情况下重现以上错误。
我引用了资源存储库的错误分支,其中该模板yaml文件不存在。
我错误输入模板yaml文件的名称,导致找不到模板yaml文件。
因此,请检查资源存储库的master分支中是否存在模板yaml文件,并确保名称模板yaml文件正确。
答案 2 :(得分:0)
我发现我需要在模板前加上/
前缀,或者它是相对于源管道模板(向我提示实际问题)而不是存储库的根。
- 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
大概是在将多个存储库指定为资源的管道之间发生了差异。
答案 3 :(得分:0)
好吧,这是一个愚蠢的,但它花了我几个小时......
yml
与 yaml
并确保您引用的是正确的!这是实际存在的文件的变体,但在“啊哈”之前我盯着这个看了一会儿