Azure devops Azure DevOps包含的yaml express未按预期工作
我这里有yaml管道示例:Azure devops Azure DevOps包含的yaml express未按预期工作,azure-devops,yaml,azure-pipelines,Azure Devops,Yaml,Azure Pipelines,我这里有yaml管道示例: name: $(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r) trigger: - test-expressions variables: folder: application1 applications: application1,application2,application3 exclude: application2 steps: - ${{ if ne('$(folder)', '') }}:
name: $(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
trigger:
- test-expressions
variables:
folder: application1
applications: application1,application2,application3
exclude: application2
steps:
- ${{ if ne('$(folder)', '') }}:
- powershell: |
Write-Host "Output the folder - $(folder)`n";
Write-Host "Output the applications - $(applications)";
displayName: folder is not blank
- ${{ if contains('$(applications)', '$(folder)') }}:
- powershell: |
Write-Host "Output the folder - $(folder)"
displayName: applications contains folder
- ${{ if contains('$(folder)', '$(applications)') }}:
- powershell: |
Write-Host "Output the folder - $(folder)"
displayName: folder contains applications
第一个任务按预期启用。但是,我希望在管道运行时也启用第二个任务。但是,它不会运行。有人知道问题出在哪里吗?要么我错误地使用了contains语法,要么它的行为不符合预期
就背景而言,我更喜欢在yaml中使用if语句而不是条件语句,因为我发现从可用性的角度来看它更好。如果可以避免,我不想在管道中显示任何跳过的任务。您应该使用以下语法:
变量['applications']
,而不是:'$(applications)
因此,它将是:
- ${{ if contains(variables['applications'], variables['folder']) }}:
谢谢正是我需要的