I have folder structure this way in source code. f1 f2 f3 f4
I have added gitcopy diff task in my pipeline which lists and copies files which are modified to a destination folder. Now, I want to have a conditional loop as powershell script to only zip those folders which have modified files with a particular names for example if files from f1 are modified..I want particular steps to be performed and so on.. How can I do it as a loop? edit: I have written my pipeline in this way. But its failing in publish step with errors as listed.
yaml: trigger:
none
pool:
vmImage: 'windows-latest'
variables:
FR1PHPPRDAPP1VFlag: false
FR1PHPPRDAPP4VFlag: false
FR1PHPPRDAPP5VFlag: false
FR1PHPPRDSRE1VFlag: false
FR1PHPPRDAPP7VFlag: false
stages:
-stage: Zipping modified folders
steps:
- powershell: |
## get the changed files
$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 'FR1PHPPRDAPP1V/*')
{
cd $(Build.ArtifactStagingDirectory)
mkdir Output -force
Compress-Archive -Path $(system.defaultworkingdirectory)/FR1PHPPRDAPP1V -DestinationPath $(Build.ArtifactStagingDirectory)/Output/APP1V.zip
##set the flag variable FR1PHPPRDAPP1VFlag to true
Write-Host "##vso[task.setvariable variable=FR1PHPPRDAPP1VFlag]true"
}
if ($name -like 'FR1PHPPRDAPP4V/*')
{
cd $(Build.ArtifactStagingDirectory)
mkdir Output -force
##achive folder FR1PHPPRDAPP4V if it is changed.
Compress-Archive -Path $(system.defaultworkingdirectory)/FR1PHPPRDAPP4V -DestinationPath $(Build.ArtifactStagingDirectory)/Output/APP4V.zip
##set the flag variable FR1PHPPRDAPP4VFlag to true
Write-Host "##vso[task.setvariable variable=FR1PHPPRDAPP4VFlag]True"
}
if ($name -like 'FR1PHPPRDAPP5V/*')
{
cd $(Build.ArtifactStagingDirectory)
mkdir Output -force
##achive folder FR1PHPPRDAPP5V if it is changed.
Compress-Archive -Path $(system.defaultworkingdirectory)/FR1PHPPRDAPP5V -DestinationPath $(Build.ArtifactStagingDirectory)/Output/APP5V.zip
##set the flag variable FR1PHPPRDAPP5VFlag to true
Write-Host "##vso[task.setvariable variable=FR1PHPPRDAPP5VFlag]True"
}
if ($name -like 'FR1PHPPRDSRE1V/*')
{
cd $(Build.ArtifactStagingDirectory)
mkdir Output -force
##achive folder FR1PHPPRDSRE1V if it is changed.
Compress-Archive -Path $(system.defaultworkingdirectory)/FR1PHPPRDSRE1V -DestinationPath $(Build.ArtifactStagingDirectory)/Output/SRE1V.zip
##set the flag variable FR1PHPPRDSRE1VFlag to true
Write-Host "##vso[task.setvariable variable=FR1PHPPRDSRE1VFlag]True"
}
if ($name -like 'FR1PHPPRDAPP7V/*')
{
cd $(Build.ArtifactStagingDirectory)
mkdir Output -force
##achive folder FR1PHPPRDAPP7V if it is changed.
Compress-Archive -Path $(system.defaultworkingdirectory)/FR1PHPPRDAPP7V -DestinationPath $(Build.ArtifactStagingDirectory)/Output/APP7V.zip
##set the flag variable FR1PHPPRDAPP7VFlag to true
Write-Host "##vso[task.setvariable variable=FR1PHPPRDAPP7VFlag]True"
}
}
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/Output'
ArtifactName: 'scripts-f2p'
publishLocation: 'Container'
condition: and(succeeded(), or(eq(variables.FR1PHPPRDAPP1VFlag, true),eq(variables.FR1PHPPRDAPP4VFlag, true),eq(variables.FR1PHPPRDAPP5VFlag, true),eq(variables.FR1PHPPRDSRE1VFlag, true),eq(variables.FR1PHPPRDAPP7VFlag, true)))