I wanted to set a condition based on the committed paths in Job level? Within my pipeline, I only want to run a particular job if a certain folder has been committed.
I have defined a path filter in my pipeline trigger
trigger:
branches:
include:
- DevopsTest
paths:
include:
- Test/*
- Prod/*
Based on the committed path I wanted to set a condition to invoke respective job to pass variables into my script inorder to deploy. If committed path is Test run the Test job and skip the other and vice versa.
Based on the This Approach i have made the changes to my 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'
However the If condition in Inline script is not getting matched with committed path and not setting the value to true
is there something i'm not doing right? or am i missing something here