将字典传递到Azure Devops yaml中的模板

发布于 2025-02-05 03:02:54 字数 1697 浏览 5 评论 0原文

我想在模板中运行一个循环,以下载带有特定版本的两个工件。

我一直在试图为此制定解决方案,但还没有运气,这就是我到目前为止出现的东西,但我认为它不受支持。

如果可能的话,有人可以将我指向正确的方向吗?

pipeline.yml

variables:
- template: project.variables.yml

jobs:
- job: 'Deploy'
  steps:
  - template: instantclient.template.yml
    parameters:
      artifacts:
        oracle-instantclient:
          package: 'oracle-instantclient'
          packageVersion: ${{ variables.oracle-instantclient }}
        oracle-data-access-components:
          package: 'oracle-data-access-components'
          packageVersion: ${{ variables.oracle-data-access-components }}

instantclient.template.yml

parameters:
- name: artifacts
  type: object
- name: feed
  default: ahitapplicationteam
- name: downloadDirectory
  default: deployment/s

steps:
  - ${{ each artifact in parameters.artifacts}}:
    - template: artifacts.template.yml
      parameters:
        packageVersion: ${{ packageVersion }}
        feed:  ${{ parameters.feed }}
        package: ${{ package }}
        downloadDirectory: ${{ parameters.downloadDirectory }}

trifacts.template.yml

parameters:
- name: packageVersion
- name: feed
- name: package
- name: downloadDirectory

steps:
- task: UniversalPackages@0
  displayName: 'Downloading | Feed: ${{ parameters.feed }} | Package: ${{ parameters.package }}' #| PackageVersion: ${{ parameters.packageVersion }}
  inputs:
    command: 'download'
    downloadDirectory: ${{ parameters.downloadDirectory }}
    vstsFeed:  ${{ parameters.feed }}
    vstsFeedPackage: ${{ parameters.package }}
    vstsPackageVersion: ${{ parameters.packageVersion }}
    verbosity: 'Debug'

I want to run a loop in a template to download two artifacts with specific versions.

I have been trying to formulate solutions for this but no luck yet, this is what I've came up until now but i think its not supported.

Can someone point me in the right direction if this is possible?

pipeline.yml

variables:
- template: project.variables.yml

jobs:
- job: 'Deploy'
  steps:
  - template: instantclient.template.yml
    parameters:
      artifacts:
        oracle-instantclient:
          package: 'oracle-instantclient'
          packageVersion: ${{ variables.oracle-instantclient }}
        oracle-data-access-components:
          package: 'oracle-data-access-components'
          packageVersion: ${{ variables.oracle-data-access-components }}

instantclient.template.yml

parameters:
- name: artifacts
  type: object
- name: feed
  default: ahitapplicationteam
- name: downloadDirectory
  default: deployment/s

steps:
  - ${{ each artifact in parameters.artifacts}}:
    - template: artifacts.template.yml
      parameters:
        packageVersion: ${{ packageVersion }}
        feed:  ${{ parameters.feed }}
        package: ${{ package }}
        downloadDirectory: ${{ parameters.downloadDirectory }}

artifacts.template.yml

parameters:
- name: packageVersion
- name: feed
- name: package
- name: downloadDirectory

steps:
- task: UniversalPackages@0
  displayName: 'Downloading | Feed: ${{ parameters.feed }} | Package: ${{ parameters.package }}' #| PackageVersion: ${{ parameters.packageVersion }}
  inputs:
    command: 'download'
    downloadDirectory: ${{ parameters.downloadDirectory }}
    vstsFeed:  ${{ parameters.feed }}
    vstsFeedPackage: ${{ parameters.package }}
    vstsPackageVersion: ${{ parameters.packageVersion }}
    verbosity: 'Debug'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我做我的改变 2025-02-12 03:02:54

您在正确的轨道上。您需要将-字符添加到对象中的每个项目中,以将其转换为数组。 对象可以是简单的字符串或复杂对象的数组。作为对象,您可以在每个循环中访问对象的属性。

使用$ {{variables.oracle-data-access-components}}}假设oracle> oracle> oracle> oracle-data-access-components变量可在 compile-上获得时间最初处理管道时。

您是否想将其分解为3个模板是一种风格决定。我使用了2个模板来简化可读性,但是第三个模板将为您提供一些验证所需的参数。

pipeline.yml

variables:
- template: project.variables.yml

jobs:
- job: 'Deploy'
  steps:
  - template: instantclient.template.yml
    parameters:
      artifacts:
        - name: 'oracle-instantclient'
          version: ${{ variables.oracle-instantclient }}
        - name: 'oracle-data-access-components'
          version: ${{ variables.oracle-data-access-components }}

intermantclient.template.yml

parameters:
# list of package to download (name, version)
- name: artifacts
  type: object

# azure artifact feed name
- name: feed
  type: string
  default: 'ahitapplicationteam'

# download path for artifacts
- name: downloadDirectory
  type: string
  default: 'deployment/s'

steps:
# loop through the artifacts (name, version)
- ${{ each artifact in parameters.artifacts}}:
 
  # download the artifact
  - task: UniversalPackages@0
    displayName: 'Downloading | Feed: ${{ parameters.feed }} | Package: ${{ artifact.name }}' #| PackageVersion: ${{ artifact.version }}
    inputs:
      command: 'download'
      downloadDirectory: ${{ parameters.downloadDirectory }}
      vstsFeed:  ${{ parameters.feed }}
      vstsFeedPackage: ${{ artifact.name }}
      vstsPackageVersion: ${{ artifact.version }}
      verbosity: 'Debug'

You're on the right track. You need to add the - character to each item in your object to convert it into an array. The object can be an array of simple strings or complex objects. As an object, you can access the properties of your objects in the each loop.

The use of ${{ variables.oracle-data-access-components }} assumes that the oracle-data-access-components variable is available at compile-time when the pipeline is initially processed.

Whether you want to break it into 3 templates is a stylistic decision. I went with 2 templates to simplify readability, but a third template will provide you will some validation for required parameters.

pipeline.yml

variables:
- template: project.variables.yml

jobs:
- job: 'Deploy'
  steps:
  - template: instantclient.template.yml
    parameters:
      artifacts:
        - name: 'oracle-instantclient'
          version: ${{ variables.oracle-instantclient }}
        - name: 'oracle-data-access-components'
          version: ${{ variables.oracle-data-access-components }}

instantclient.template.yml

parameters:
# list of package to download (name, version)
- name: artifacts
  type: object

# azure artifact feed name
- name: feed
  type: string
  default: 'ahitapplicationteam'

# download path for artifacts
- name: downloadDirectory
  type: string
  default: 'deployment/s'

steps:
# loop through the artifacts (name, version)
- ${{ each artifact in parameters.artifacts}}:
 
  # download the artifact
  - task: UniversalPackages@0
    displayName: 'Downloading | Feed: ${{ parameters.feed }} | Package: ${{ artifact.name }}' #| PackageVersion: ${{ artifact.version }}
    inputs:
      command: 'download'
      downloadDirectory: ${{ parameters.downloadDirectory }}
      vstsFeed:  ${{ parameters.feed }}
      vstsFeedPackage: ${{ artifact.name }}
      vstsPackageVersion: ${{ artifact.version }}
      verbosity: 'Debug'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文