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

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

问题描述

仍然试图全面了解Azure管道以及我可以使用这些管道做什么...

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

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

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.

使用此YAML,我可以构建和打包该工具:

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'

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

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?

谢谢!

推荐答案

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

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.但是要获取日期时间,可以使用

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

我的工作样本:

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'

有关使用BuildNumber获取日期的更多详细信息,可以检查

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

结果:

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

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天全站免登陆