【发布时间】:2020-12-01 10:06:55
【问题描述】:
我在源代码中有这种文件夹结构。 f1 f2 f3 f4
我在管道中添加了 gitcopy diff 任务,该任务列出并复制修改到目标文件夹的文件。 现在,我希望有一个条件循环作为 powershell 脚本,以仅压缩那些修改了具有特定名称的文件的文件夹,例如,如果 f1 中的文件被修改..我想要执行特定的步骤等等.. 我怎么能做一个循环? 编辑:我以这种方式编写了我的管道。但它在发布步骤中失败,并出现所列错误。
yaml: 触发器:
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)))
【问题讨论】:
标签: azure-devops azure-pipelines pipeline