所以我一直在研究Azure DevOps Yaml Pipelines,但遇到了一个我似乎无法弄清楚是什么原因的问题。
我正在为小型类库解决方案构建我的第一个管道,其想法是在将更改提交到主库后还原,构建,测试,打包和发布它。
我将部署的不同部分分为多个阶段/任务(这可能不是使用它们的正确方法),但是当我这样做时,“ Nuget pack”步骤将永远找不到任何已构建的文件。 / p>
此YAML无法正常工作,并在“ NuGet(Pack)”步骤上出错,因为它找不到“ projects.assets.json”文件,该文件我已经确认生成了该步骤。
trigger:
- master
pool:
vmImage: 'windows-latest'
name: 'Set dynamically'
variables:
buildConfiguration: 'Release'
version.Major: 1
version.Minor: $[counter(variables['version.Major'], 0)]
version.Patch: 0
version.Revision: $[counter(variables['version.Minor'], 0)]
version.Number: '$(version.Major).$(version.Minor).$(version.Patch).$(version.Revision)'
stages:
- stage: Prepare
jobs:
- job: Prepare_Sources
steps:
- checkout: self
clean: true
- job: Prepare_BuildAndVersionNumbers
steps:
- task: PowerShell@2
displayName: Set the name of the build
inputs:
targetType: 'inline'
script: |
[string] $dateTime = (Get-Date -Format 'yyyyMMdd')
[string] $buildName = "$(Build.DefinitionName)_$(Build.SourceBranchName)_$($dateTime)_$(version.Number)"
Write-Host "Setting the name of the build to '$buildName'."
Write-Host "##vso[build.updatebuildnumber]$buildName"
- stage: Build
jobs:
- job: BuildRestore
steps:
- task: NuGetCommand@2
displayName: 'Restore (NuGet)'
inputs:
command: restore
restoreSolution: '**\*.sln'fs
feedsToUse: select
includeNuGetOrg: true
vstsFeed: 'internalfeed1'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- task: DotNetCoreCLI@2
displayName: 'Restore (.NET Core)'
inputs:
command: restore
includeNuGetOrg: true
nobuild: true
vstsFeed: 'internalfeed1'
nuGetFeedType: internal
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- task: DotNetCoreCLI@2
displayName: 'Build all projects in solution'
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- stage: Test
jobs:
- job: Test_UnitTests
steps:
- task: DotNetCoreCLI@2
displayName: 'Run & Analyse UnitTests'
inputs:
command: test
projects: '**/*Tests/*UnitTests.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
- stage: Package
jobs:
- job: Package_Nuget
steps:
- task: NuGetAuthenticate@0
displayName: "Nuget (Authenticate)"
- task: DotNetCoreCLI@2
displayName: 'NuGet (Package)'
inputs:
nobuild: true
command: pack
packagesToPack: '**/*.csproj'
versioningScheme: byBuildNumber
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'NuGet (Publish)'
inputs:
command: push
searchPatternPush: '$(Build.ArtifactStagingDirectory)/*.nupkg;'
feedPublish: 'internalfeed1'
如果我将其简化为一项单独的工作,而没有阶段/工作,则部署一切正常(如下所示)
trigger:
- master
pool:
vmImage: 'windows-latest'
name: 'Set dynamically'
variables:
buildConfiguration: 'Release'
version.Major: 1
version.Minor: $[counter(variables['version.Major'], 0)]
version.Patch: 0
version.Revision: $[counter(variables['version.Minor'], 0)]
version.Number: '$(version.Major).$(version.Minor).$(version.Patch).$(version.Revision)'
steps:
- checkout: self
clean: true
- task: PowerShell@2
displayName: Set the name of the build
inputs:
targetType: 'inline'
script: |
[string] $dateTime = (Get-Date -Format 'yyyyMMdd')
[string] $buildName = "$(Build.DefinitionName)_$(Build.SourceBranchName)_$($dateTime)_$(version.Number)"
Write-Host "Setting the name of the build to '$buildName'."
Write-Host "##vso[build.updatebuildnumber]$buildName"
- task: NuGetCommand@2
displayName: 'Restore (NuGet)'
inputs:
command: restore
restoreSolution: '**\*.sln'fs
feedsToUse: select
includeNuGetOrg: true
vstsFeed: 'internalfeed1'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- task: DotNetCoreCLI@2
displayName: 'Restore (.NET Core)'
inputs:
command: restore
includeNuGetOrg: true
nobuild: true
vstsFeed: 'internalfeed1'
nuGetFeedType: internal
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- task: DotNetCoreCLI@2
displayName: 'Build all projects in solution'
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- task: DotNetCoreCLI@2
displayName: 'Run & Analyse UnitTests'
inputs:
command: test
projects: '**/*Tests/*UnitTests.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
- task: DotNetCoreCLI@2
displayName: 'NuGet (Package)'
inputs:
nobuild: true
command: pack
packagesToPack: '**/*.csproj'
versioningScheme: byBuildNumber
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'NuGet (Publish)'
inputs:
command: push
searchPatternPush: '$(Build.ArtifactStagingDirectory)/*.nupkg;'
feedPublish: 'internalfeed1'
在这些谜题的文档中找不到答案,可以解释为什么当分解为各个阶段/工作时,它为什么不起作用,有人知道原因是什么吗?阶段/工作是否不应该以这种方式进行交互?
谢谢
答案 0 :(得分:1)
这是因为每个作业都在不同的代理上运行
一个阶段包含一个或多个工作。每个作业都在代理上运行。作业代表一组步骤的执行边界。所有步骤都在同一代理上一起运行。例如,您可以构建两个配置-x86和x64。在这种情况下,您有一个构建阶段和两个作业。
这是因为jon是步骤集的边界,所以源代码之间没有共享。因此,如果您需要将其作为单独的工作和阶段保存,则应在每个工作checkout
步骤中重复
- checkout: self
clean: true
请阅读this有关管道的基础知识,它们将为您提供有关其工作原理的高级视图。
如果您想在工作之间共享一些工件,请查看here。
如果需要在阶段之间共享一些变量,我写了一篇有关this的文章。