Azure Pipeline:在同一池中的同一代理上创建作业 运行

Azure Pipeline: Make Jobs run on the same Agent from the same pool

我有一个看起来像这样的 YAML 脚本:

jobs:
- job: UnixBuild
  pool: 
    name: BuildMachinesUnix
  steps:
  - bash: echo "Build Unix"

- job: WinBuild
  pool: 
    name: BuildMachinesWindows
  steps:
  - bash: echo "Build Windows"

- job: UnixRelease
  dependsOn:
    - UnixBuild
    - WinBuild
  condition: and(succeeded('UnixBuild'), succeeded('WinBuild'))
  pool: 
    name: BuildMachinesUnix
  steps:
  - bash: echo "Release on Unix"

- job: WinRelease
  dependsOn:
    - UnixBuild
    - WinBuild
  condition: and(succeeded('UnixBuild'), succeeded('WinBuild'))
  pool: 
    name: BuildMachinesWindows
  steps:
  - bash: echo "Release on Windows"

每个池都有几个代理,我希望承担 UnixBuild 作业的代理也处理 UnixRelease 作业,因为该版本的所有文件都在那里,所以我不需要重建它,在发布步骤,WindowsBuild

也是如此

这样的事情可能吗,如果可能怎么办?

如果没有,关于如何只在 Unix 和 Windows 都成功时才发布,而不必编译两次,有什么好的建议吗?

I want the Agent that took on the UnixBuild job to also handle the UnixRelease job, as all the files for that release is there, so that I don't needto rebuild it, in the release step, and the same goes from the WindowsBuild

答案是肯定的。

要解决这个问题,我们可以从 UnixBuild 作业中获取代理名称,然后将其作为 demands:

  - job: UnixBuild
    pool: 
      name: BuildMachinesUnix
    steps:
    - bash: echo "$(Agent.Name)"
    - bash: |
        echo "##vso[task.setvariable variable=someName;isOutput=true;]$(Agent.Name)"
      name: setVariable

  - job: UnixRelease
    dependsOn:
      - UnixBuild
      - WinBuild
    condition: and(succeeded('UnixBuild'), succeeded('WinBuild'))
    variables: 
      TestsomeName: $[ dependencies.UnixBuild.outputs['setVariable.someName'] ]
    pool: 
      name: BuildMachinesUnix
      demands:
      - Agent.Name -equals $(TestsomeName)
    steps:
    - bash: echo "$(TestsomeName)"