将数组作为输入传递给 Azure DevOps YAML 任务

Pass array as inputs to Azure DevOps YAML task

我正在尝试配置一个 CI,它将在 Azure DevOps 上生成 NuGet 包作为工件(稍后将推送到我的 NuGet 服务器)。

为此,我在 Azure DevOps 上使用 Builds Pipelines,即 YAML 版本。

我有 3 个项目需要构建包。我正在使用 NuGetCommand@2 来完成这项任务:

- task: NuGetCommand@2
  inputs:
    command: pack
    packagesToPack: $(Build.SourcesDirectory)/src/HTS_MessageEngine.Communication/HTS_MessageEngine.Communication.csproj
    majorVersion: $(majorVersion)
    minorVersion: $(minorVersion)
    patchVersion: $(patchVersion)
    versioningScheme: byPrereleaseNumber

但是,对于每个项目,我必须将此块复制 3 次。有没有办法在 packagesToPack 参数中指定一组项目?到目前为止,每个包的版本都是相同的,所以我不需要三个不同的块...

注意:这3个项目都是3个NetStandard,包构建的属性直接存储在csproj中

您可以使用每个功能(如果此时可用):

# my-template.yml
parameters:
steps:
- ${{ each project in parameters.projects }}:
  - task: PublishBuildArtifacts@1
    displayName: Publish ${{ project }}
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/${{ project }}.zip'
# ci.yml
steps:
- template: my-template.yml
  parameters:
    projects:
    - test1
    - test2

Github 此功能的 PR:https://github.com/Microsoft/azure-pipelines-yaml/pull/2#issuecomment-452748467

对于上面的代码我得到了这个异常运行一个构建:

my-template.yml (Line: 1, Col: 12): Unexpected value ''

但这对我有用:

# my-template.yml
parameters:
- name: projects
  type: object
  default: {}
steps:
- ${{ each project in parameters.projects }}:
  - task: PublishBuildArtifacts@1
    displayName: 'Publish ${{ project }}
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/${{ project }}.zip'

然后:

# ci.yml
steps:
- template: my-template.yml
  parameters:
    projects:
    - test1
    - test2