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

问题描述

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

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

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

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

请告诉我如何使用 -condition 或是否有其他替代方法来实现此目的

下面是我的 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')

任何帮助将不胜感激

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)