您在寻找有条件的容器工作吗?查看我的脚本:
parameters:
- name: isSelfHosted
displayName: isSelfHosted
type: boolean
default: true
values:
- false
- true
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
${{ if not(parameters.isSelfHosted) }}:
container: mcr.microsoft.com/dotnet/core/sdk:2.2
steps:
- task: CmdLine@2
inputs:
script: |
echo 2.2 SDK
${{ if eq(parameters.isSelfHosted, 'true') }}:
container: mcr.microsoft.com/dotnet/core/sdk:2.1
steps:
- task: CmdLine@2
inputs:
script: |
echo 2.1 SDK
我可以通过参数值选择哪个容器(.net core 2.1 或 .net core 2.2)isSelfHosted
。
它使用运行时参数,因此我可以在运行管道时管理条件(选中或取消选中该框):
更新:
请参阅带有参数的作业、阶段和步骤模板
将以下内容移动到模板文件中:
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
${{ if not(parameters.isSelfHosted) }}:
container: mcr.microsoft.com/dotnet/core/sdk:2.2
steps:
- task: CmdLine@2
inputs:
script: |
echo 2.2 SDK
${{ if eq(parameters.isSelfHosted, 'true') }}:
container: mcr.microsoft.com/dotnet/core/sdk:2.1
steps:
- task: CmdLine@2
inputs:
script: |
echo 2.1 SDK
那么主要azure-pipelines.yml
应该是
parameters:
- name: isSelfHosted
displayName: isSelfHosted
type: boolean
default: true
values:
- false
- true
stages:
- template: templates/xxx.yml # Template reference
parameters:
isSelfHosted: xxx (Value of isSelfHosted parameter)