在 Azure Pipelines 构建中命名生成的 ZIP 存档? [英] Naming resulting ZIP archive in Azure Pipelines build?

查看:19
本文介绍了在 Azure Pipelines 构建中命名生成的 ZIP 存档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仍在尝试全面掌握 Azure Pipelines 以及我可以用它们做什么...

我终于设法使用 Azure Pipelines 构建了我的小型 .NET Core 命令行实用程序 - 现在尝试将其发布为构建工件.

使用这个 YAML,我可以构建和打包工具:

- 任务:DotNetCoreCLI@2显示名称:'dotnet 构建'输入:命令:'构建'项目:'$(解决方案)'- 任务:DotNetCoreCLI@2displayName: 'dotnet 发布'输入:命令:发布发布WebProjects:错误参数:'--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'zipAfterPublish: 真- 任务:PublishBuildArtifacts@1输入:pathtoPublish: '$(Build.ArtifactStagingDirectory)'工件名称:'MyTool_LatestBuild'

但在已发布的构建工件中,我只得到一个文件 a.zip - 有什么方法可以影响该 ZIP 存档的名称?我真的很想拥有 MyTool_2020_Sep_08.zipMyTool_v1.5.7.zip 之类的东西......但我该怎么做?似乎在互联网上的任何地方都找不到任何非常有用的东西......任何输入?

谢谢!

解决方案

1. 同意 Vernou.您可以通过指定包含二进制文件的文件夹名称来自定义名称.所以我们需要修改dotnet publish步骤的--output参数和PublishBuildArtifacts步骤的PathtoPublish参数.

2.但是要获取日期时间,可以使用

我们可以通过修改我们定义Build.BuildNumber的方式来控制格式(在Yaml中,它是name).如果我们定义 name: $(Date:yyyyMMdd),那么输出的 zip 将是 MyTool_20200908.zip.

Still trying to get a full grasp on the Azure Pipelines and what I can do with those...

I've managed to finally get my little .NET Core command line utility built with Azure Pipelines - now trying to publish it as a build artifact.

With this YAML, I can build and package the tool:

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    command: 'build'
    projects: '$(solution)'

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: publish
    publishWebProjects: False
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)' 
    artifactName: 'MyTool_LatestBuild'

But in the published build artifacts, I only get a file a.zip - is there any way I can influence the name of that ZIP archive?? I'd really love to have something like MyTool_2020_Sep_08.zip or MyTool_v1.5.7.zip something.... but how can I do that?? Can't seem to find anything very useful anywhere on the interwebs ... any inputs?

Thanks!

解决方案

1.Agree with Vernou. You can customize the name by specifying the folder name that contains your binaries. So we need to modify the --output argument of dotnet publish step and PathtoPublish argument of PublishBuildArtifacts step.

2.But to get Date time, you can use Build.BuildNumber which is predefined variables.

My working sample:

name: $(Date:yyyyMMdd)$(Rev:.r)

steps:
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: publish
    publishWebProjects: False
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/MyTool_$(Build.BuildNumber)'
    zipAfterPublish: True

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)/MyTool_$(Build.BuildNumber)'
    ArtifactName: 'MyTool_LatestBuild'
    publishLocation: 'Container'

More details about using BuildNumber to get date, you can check Configure run or build numbers.

The result:

We can control the format via modifying how we define the Build.BuildNumber(In Yaml, it's name). If we define name: $(Date:yyyyMMdd), then the output zip would be MyTool_20200908.zip.

这篇关于在 Azure Pipelines 构建中命名生成的 ZIP 存档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆