gpt4 book ai didi

azure-devops - 将字典传递给 azure devops yaml 中的模板

转载 作者:行者123 更新时间:2023-12-05 04:28:49 24 4
gpt4 key购买 nike

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

我一直在尝试为此制定解决方案,但还没有成功,这是我到现在才想到的,但我认为它不受支持。

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

管道.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 }}

工件.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'

最佳答案

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

使用 ${{ variables.oracle-data-access-components }} 假定 oracle-data-access-components 变量在 编译时 最初处理管道时。

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

管道.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'

关于azure-devops - 将字典传递给 azure devops yaml 中的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72522822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com