如何配置基于条件的管道| Azure管道

如何配置基于条件的管道| Azure管道,azure,azure-devops,azure-pipelines-yaml,azure-pipelines-tasks,Azure,Azure Devops,Azure Pipelines Yaml,Azure Pipelines Tasks,我遇到了一个场景,我想根据源目录构建源代码 我在同一个git存储库中有两种语言(dotnet和Python) 我想使用单个Azure管道构建源代码 如果两个(dotnet和Python)都完成了提交,那么应该执行所有任务 &如果对特定目录执行了提交,则只应执行相应的语言 请告诉我如何使用-条件或是否有其他替代方案来实现这一点 下面是我的azure-pipelines.yml #Trigger and pool name configuration variables: name: files

我遇到了一个场景,我想根据源目录构建源代码

我在同一个git存储库中有两种语言(dotnet和Python)

我想使用单个Azure管道构建源代码

如果两个(dotnet和Python)都完成了提交,那么应该执行所有任务 &如果对特定目录执行了提交,则只应执行相应的语言

请告诉我如何使用
-条件
或是否有其他替代方案来实现这一点

下面是我的azure-pipelines.yml

#Trigger and pool name configuration
variables:
  name: files 
steps:
- script: $(files) = git diff-tree --no-commit-id --name-only -r $(Build.SourceVersion)"
  displayName: 'display Last Committed Files'
  ## Here I am getting changed files
  ##Dotnet/Server.cs
  ##Py/Hello.py

- task: PythonScript@0   ## It should only get called when there are changes in /Py
  inputs:
    scriptSource: 'inline'
    script: 'print(''Hello, FromPython!'')'
    condition: eq('${{ variables.files }}', '/Py')  
- task: DotNetCoreCLI@2  ## It should only get called when there are changes in /Dotnet
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    condition: eq('${{ variables.files }}', '/Dotnet')

任何帮助都将不胜感激

我认为不可能直接做你想做的事。所有这些任务条件都在管道执行开始时进行评估。因此,如果在任何特定任务中设置管道变量,即使是第一个任务,也已经太晚了

如果你真的想做这件事,你可能需要一直编写脚本。因此,您可以使用以下语法在第一个脚本中设置变量:

然后在其他脚本中对其进行评估,如:

if $(DotNet) = 'true' then dotnet build

在这些行中有一些东西。这可能相当微妙,因此在更高的层次上重新考虑流程可能是有意义的,但如果没有额外的背景,很难说。

这可能就是您所看到的:这是否回答了您的问题?
if $(DotNet) = 'true' then dotnet build