azure - 如何配置基于条件的管道 | Azure 管道
问题描述
我遇到了一个场景,我想根据源目录构建源代码。
我在同一个 git 存储库(dotnet 和 Python)中有 2 种语言。
我想使用单个 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')
任何帮助将不胜感激
解决方案
我认为不可能直接做你想做的事。所有这些任务条件都在管道执行开始时进行评估。因此,如果您在任何特定任务中设置管道变量,即使是第一个任务,也为时已晚。
如果您真的想这样做,您可能必须一直编写脚本。因此,您使用此处的语法在第一个脚本中设置变量:
(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
这些线之间的东西。这可能会非常微妙,因此在更高级别重新考虑流程可能是有意义的,但如果没有额外的上下文,很难说。
推荐阅读
- python - 如果仅使用两个级别,则 Matplotlib 轮廓孵化不起作用
- javascript - 为什么元素无法垂直居中对齐
- f# - F# 函数名称和指向该名称的函数值之间的区别
- gradle - 在 gradle 中是否可以发现给定 Maven 存储库中的哪些工件取决于给定“组:模块”的任何版本?
- makefile - Make:提取跟随已知路径的目标路径段
- python - 运算符字符串“array_contains”无效
- ios - 输入无效参数时 UUIDWithString 崩溃
- javascript - 如何处理由数组呈现的组件中一个元素/索引的样式?
- scala - 当两个ID在Scala中具有相同的最高价格时,以较小的ID获得最高价格
- docker - Docker swarm 模式路由网格无法按预期工作