尝试从 Azure CI/CD 获取构建输出项目

Trying to get build output artifacts from Azure CI/CD

我一定是变老了 - 或者别的什么....但我无法理解我在这里想做的事情。

我有一个相当简单的 .NET Core 命令行实用程序,代码托管在 Azure Devops Git 存储库中,并且我已经通过构建管道在 Azure Devops 中设置了持续集成。这就像一个魅力 - 新的检查进来了,代码被编译并且单元测试得到 运行 - 太棒了。

但下一步似乎让我望而却步。我来自 CruiseControl 或 Atlassian Bamboo 等工具,我们曾经有一个单独的“测试”构建 - 一个可以手动触发的,做同样的事情(构建代码,运行 测试)和然后将构建输出打包成某种“工件”——一个 ZIP 文件,一个 MSI 安装程序——随便什么。

我试图在 Azure Devops 中完成同样的事情 - 但我似乎只见树木不见森林....

这里有“工件”部分 - 很自然地,我认为向我的构建管道添加另一个步骤并根据需要获得我的结果将是一件轻而易举的事。但无论我做什么,我尝试什么——“存档文件”、“已发布的构建工件”或我偶然发现的任何其他内容,我似乎无法将我的构建结果转化为表格,以便我可以从 Azure 下载它构建完成后 Devops。

我到底需要做什么??我期待能够进入“工件”并以某种方式选择我的构建并获得我的输出 - 作为 ZIP 或其他 - 但情况似乎并非如此。 “工件”要求提要 - 如 NuGet 或 Maven 提要,如果我理解正确的话 - 但这不是我在这里追求的......

哪里有一篇写得非常好的博客 post 或可以解释如何设置的教程?

到目前为止,我构建的 YAML 如下所示:

# .NET Desktop

trigger:
- none

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

然后我尝试了“存档文件”步骤:

# Archive files - compress files into .7z, .tar.gz, or .zip
- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.BinariesDirectory)' 
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' 
    replaceExistingArchive: true 
    verbose: 1

还有“已发布的管道工件”:

- task: PublishPipelineArtifact@1
  inputs:
    targetPath: '$(Pipeline.Workspace)'
    artifact: 'BfhInfoPackage'
    publishLocation: 'pipeline'

但在这两种情况下,我都发现任何“结果”都显示在任何地方供我下载或获取....

你看过发布的文件夹了吗?

当我第一次遇到 azure pipelines 时,我花了一段时间才找到这个位置。

Azure Artifacts 是一个提要,在将它们发布到提要之前,您不会找到您的常规项目。如果你想发布你的工件供以后使用,你应该使用这两个任务之一:

建议使用第一个任务,因为它同时支持多阶段和经典发布管道。

查看您的存档定义,我看到您在此处发布了您的工件 $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip,但您正在尝试发布 '$(Pipeline.Workspace)'。请将您的 targetPath 更改为 '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' ,您应该能够在@Stefan 提到的地方看到您的工件。

关闭此 targetPath 是:

The path of the file or directory to publish. Can be absolute or relative to the default working directory. Can include variables, but wildcards are not supported.

Where's that one amazingly well written blog post or tutorial that can explain how to set this up?

根据文档Overview of artifacts in Azure Pipelines

You can publish and consume many different types of packages and artifacts with Azure Pipelines. Your continuous integration/continuous deployment (CI/CD) pipeline can publish specific package types to their respective package repositories (NuGet, npm, Python, and so on). Or you can use build artifacts and pipeline artifacts to help store build outputs and intermediate files between build steps. You can then add onto, build, test, or even deploy those artifacts.

因此,Azure Pipelines 中的工件类型可以是特定的包存储库(NuGet、npm、Python 等),也可以存储构建输出和中间文件。

那么我们需要针对不同类型的工件采取不同的处理方法。如果我们的工件是一个特定的包存储库,那么我们通常使用 nuget pack/publishmaven publish 等任务将工件发布到相应的提要。但如果工件只是构建步骤之间的中间文件,那么我们需要手动处理这些输出,将我们想要的内容打包并发布到工件中。这个过程可以简单的看成select个文件和发布神器。通常我们会使用copy filePublishBuildArtifacts这两个任务来完成它。 Copy file 将文件复制到我们定义的一个文件夹中,默认是$(build.artifactstagingdirectory),然后PublishBuildArtifacts任务会把它发布到Azure Pipelines,这样我们就可以在azure pipeline中直接下载了构建结果。

您可以查看文档 Artifacts in Azure Pipelines 了解更多详情。