【发布时间】:2021-09-28 16:38:24
【问题描述】:
我想根据作业级别中的已提交路径设置条件?在我的管道中,我只想在某个文件夹已提交的情况下运行一个特定的作业。
我在管道触发器中定义了一个路径过滤器
trigger:
branches:
include:
- DevopsTest
paths:
include:
- Test/*
- Prod/*
基于提交的路径,我想设置一个条件来调用相应的作业以将变量传递到我的脚本中以便进行部署。如果提交的路径是测试,则运行测试作业并跳过另一个,反之亦然。
基于This 方法,我对我的 Yaml 进行了更改。
variables:
- group: Test
- group: Prod
stages:
- stage: CICDPolicyDeployment
jobs:
- job: CICDFlow
steps:
- task: PowerShell@2
name: folderupdate
inputs:
targetType: 'inline'
script: |
$files=$(git diff HEAD HEAD~ --name-only)
$temp=$files -split ' '
$count=$temp.Length
echo "Total changed $count files"
For ($i=0; $i -lt $temp.Length; $i++)
{
$name=$temp[$i]
echo "this is $name file"
if ($name -like "Test/*")
{
Write-Host "##vso[task.setvariable variable=TestUpdate]True"
}
}
- job: Test
condition: and(succeeded(), eq(variables['TestUpdate'], 'True'))
steps:
- task: AzurePowerShell@5
inputs:
azureSubscription: 'test'
ScriptType: 'FilePath'
ScriptPath: '.\scripts\pipelinescript.ps1'
ScriptArguments: -NAME $(testtname) -API_KEY $(testapikey) -DEPLOY_KEY $(testdeploykey)
azurePowerShellVersion: 'LatestVersion'
- job: Prod
condition: and(succeeded(), eq(variables['ProdUpdate'], 'True'))
steps:
- task: AzurePowerShell@5
inputs:
azureSubscription: 'prod'
ScriptType: 'FilePath'
ScriptPath: '.\scripts\pipelinescript.ps1'
ScriptArguments: -NAME $(Prodtname) -API_KEY $(Prodapikey) -DEPLOY_KEY $(proddeploykey)
azurePowerShellVersion: 'LatestVersion'
但是内联脚本中的 If 条件没有与提交的路径匹配并且没有将值设置为 true
有什么我做的不对吗?还是我在这里遗漏了什么
【问题讨论】:
-
@KrzysztofMadej 我已将 Yaml 代码更改为方法,但仍有一些问题
标签: azure-devops yaml azure-pipelines