多个矩阵选项的Azure DevOps管道交叉产品

发布于 2025-02-08 14:38:04 字数 1123 浏览 4 评论 0原文

Azure Devops管道文档提供了使用矩阵构建两个不同的OS和版本组合的示例:

strategy:
  matrix:
    jdk10_linux:
      imageName: "ubuntu-latest"
      jdkVersion: "1.10"
    jdk11_windows:
      imageName: "windows-latest"
      jdkVersion: "1.11"

请参见在这里

问题:有没有办法获得多组矩阵选项的交叉产品。假设我想要这个:

strategy:
  matrix:
    jdk10_linux:
      imageName: "ubuntu-latest"
      jdkVersion: "1.10"
    jdk11_linux:
      imageName: "ubuntu-latest"
      jdkVersion: "1.11"
    jdk10_windows:
      imageName: "windows-latest"
      jdkVersion: "1.10"
    jdk11_windows:
      imageName: "windows-latest"
      jdkVersion: "1.11"

除了复制并粘贴整个列表外,还有一种清洁/更简单的方法吗?

从逻辑上讲,我希望能够说更多的话:

imageList: ['windows-latest', 'ubuntu-latest']
jdkList: ['1.10', '1.11']
optionList: ['a','b','c']

strategy:
  matrix_combine_lists:
    imageName: imageList
    jdkVersion: jdkList
    someOption: optionList

The Azure DevOps pipeline documentation provides an example of using matrix to build two different OS and version combinations:

strategy:
  matrix:
    jdk10_linux:
      imageName: "ubuntu-latest"
      jdkVersion: "1.10"
    jdk11_windows:
      imageName: "windows-latest"
      jdkVersion: "1.11"

see here

Question: Is there a way to get a cross-product of multiple sets of matrix options. Suppose for example, I want this:

strategy:
  matrix:
    jdk10_linux:
      imageName: "ubuntu-latest"
      jdkVersion: "1.10"
    jdk11_linux:
      imageName: "ubuntu-latest"
      jdkVersion: "1.11"
    jdk10_windows:
      imageName: "windows-latest"
      jdkVersion: "1.10"
    jdk11_windows:
      imageName: "windows-latest"
      jdkVersion: "1.11"

Is there a cleaner/easier way to do this besides copy and paste the entire list?

Logically, I'd like to be able to say something more like:

imageList: ['windows-latest', 'ubuntu-latest']
jdkList: ['1.10', '1.11']
optionList: ['a','b','c']

strategy:
  matrix_combine_lists:
    imageName: imageList
    jdkVersion: jdkList
    someOption: optionList

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

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

发布评论

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

评论(1

浅忆 2025-02-15 14:38:04

我不确定是否可以使用矩阵,但是矩阵只是与另一组参数并行运行作业,因此使用每个模板表达式也应该工作:

parameters:
- name: imageList
  type: object
  default: ['windows-latest', 'ubuntu-latest']
- name: jdkList
  type: object
  default: ['1.10', '1.11']
- name: optionList
  type: object
  default: ['a','b','c']

jobs:
- ${{ each image in parameters.imageList }}:
  - ${{ each jdk in parameters.jdkList }}:
    - ${{ each option in parameters.optionList }}:
      - job: ${{ replace(image, '-', '_') }}_${{ replace(jdk, '.', '_') }}_${{ option }}
        pool:
          vmImage: ${{ image }}
        steps:
        - script: |
            echo "Image: ${{ image }}, jdk: ${{ jdk }}, option: ${{ option }}"

”

I am not sure if it is possible using matrix but matrix is just about running jobs in parallel with a different set of parameters so using Each Template Expression should work as well:

parameters:
- name: imageList
  type: object
  default: ['windows-latest', 'ubuntu-latest']
- name: jdkList
  type: object
  default: ['1.10', '1.11']
- name: optionList
  type: object
  default: ['a','b','c']

jobs:
- ${{ each image in parameters.imageList }}:
  - ${{ each jdk in parameters.jdkList }}:
    - ${{ each option in parameters.optionList }}:
      - job: ${{ replace(image, '-', '_') }}_${{ replace(jdk, '.', '_') }}_${{ option }}
        pool:
          vmImage: ${{ image }}
        steps:
        - script: |
            echo "Image: ${{ image }}, jdk: ${{ jdk }}, option: ${{ option }}"

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文