如何解决如何配置基于条件的管道 | 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')
任何帮助将不胜感激
解决方法
我认为直接做你想做的事情是不可能的。所有这些任务条件都在流水线执行开始时进行评估。因此,如果您在任何特定任务中设置管道变量,即使是第一个任务,也为时已晚。
如果您真的想这样做,您可能必须一路编写脚本。因此,您使用 here:
中的语法在第一个脚本中设置变量(if there are C# files) echo '##vso[task.setvariable variable=DotNet]true'
(if there are Py files) echo '##vso[task.setvariable variable=Python]true'
然后在其他脚本中,您可以像这样评估它们:
if $(DotNet) = 'true' then dotnet build
这几行之间的一些东西。这可能会很微妙,所以也许在更高层次上重新考虑流程是有意义的,但如果没有额外的背景,就很难说。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。