选择模板引用时,yaml 管道中的条件不起作用

Condition in yaml pipeline doesnt work when selecting template reference

我正在尝试在 azure 管道中使用条件,当它与 condition: 一起用于步骤时它工作正常,但是当尝试将相同条件与 if 一起使用时它不起作用并且总是从 else 块执行代码。

jobs:
- job:
  timeoutInMinutes: 100
  cancelTimeoutInMinutes: 10
  strategy:
   matrix:
    AAA_1:
      build: "dev"
    BBB_1:
      build: "release"
    BBB_2:
      build: "rc-1"
 steps:
 - checkout: repo-to-checkout
   fetchDepth: 1
   path: s/path-to-checkout
   clean: true
   condition: startsWith(variables['Agent.JobName'], 'BBB_')  #works here

 - ${{ if startsWith(variables['Agent.JobName'], 'BBB_') }}:  #doesnt work here, always go to else block
   - template: build-template.yml@templates
     parameters:
      param1: $(build)
 - ${{ else }}:
   - template: build-another-template.yml@templates
     parameters:
      param1: $(build)

我也试过 ${{ if startsWith('$(Agent.JobName)', 'BBB_') }}: 但它总是执行 else 块中的代码。

恐怕代理变量不适用于模板表达式。我在文档中找不到,但这应该证明该声明:

- job: PipelineVariablesViaExpression
  strategy:
    matrix:
      linux:
        imageName: 'ubuntu-latest'
      mac:
        imageName: 'macOS-latest'
      windows:
        imageName: 'windows-latest'
  steps:
  - pwsh: Write-Host "${{ convertToJson(variables) }}"
    displayName: 'Print all variables via expression'

然后我得到:

{
   system: build,
  system.hosttype: build,
  system.servertype: Hosted,
  system.pipelineStartTime: 2021-09-22 18:28:06+00:00,
  system.teamProject: DevOps Dojo,
  system.teamProjectId: c0a01e9c-d88c-419c-b063-1e0958c965ed,
  system.definitionId: 276,
  build.definitionName: Display pipeline variables,
  build.definitionVersion: 2,
  build.queuedBy: Krzysztof Madej,
  build.queuedById: daec281a-9c41-4c66-91b0-8146285ccdcb,
  build.requestedFor: Krzysztof Madej,
  build.requestedForId: daec281a-9c41-4c66-91b0-8146285ccdcb,
  build.requestedForEmail: krzysztof.madej@hotmail.com,
  build.sourceVersion: 65adfe640db9439312b6354f13b51eceacc2b22a,
  build.sourceBranch: refs/heads/main,
  build.sourceBranchName: main,
  build.reason: Manual,
  system.pullRequest.isFork: False,
  system.jobParallelismTag: Public,
  system.enableAccessToken: SecretVariable,
  DB_HOSTNAME: 10.123.56.222,
  DB_PORTNUMBER: 1521,
  USERNAME: TEST,
  PASSWORD: TEST,
  SCHEMANAME: SCHEMA,
  ACTIVEMQNAME: 10.123.56.223,
  ACTIVEMQPORT: 8161
}

例如,关于构建变量,您有关于此的信息: