如何从PowerShell脚本调用Azure Devops任务?
我在存储库中有许多子文件夹,它们都包含Azure ARM模板(文件夹名称=资源组) 我试图迭代每个文件夹,然后从该文件夹的内容创建一个管道工件 如何从PowerShell脚本调用devops任务?下面的脚本给出一个错误,说明未找到如何从PowerShell脚本调用Azure Devops任务?,powershell,azure-devops,azure-pipelines,Powershell,Azure Devops,Azure Pipelines,我在存储库中有许多子文件夹,它们都包含Azure ARM模板(文件夹名称=资源组) 我试图迭代每个文件夹,然后从该文件夹的内容创建一个管道工件 如何从PowerShell脚本调用devops任务?下面的脚本给出一个错误,说明未找到PublishPipelineArtifact任务 foreach ($folder in (Get-ChildItem -Path $env:SYSTEM_DEFAULTWORKINGDIRECTORY -Directory -ErrorAction Silently
PublishPipelineArtifact
任务
foreach ($folder in (Get-ChildItem -Path $env:SYSTEM_DEFAULTWORKINGDIRECTORY -Directory -ErrorAction SilentlyContinue | Select-Object Name))
{
Write-Host "Processing folder $($folder.Name)..."
Write-Host "##vso[task.PublishPipelineArtifact targetPath=$folder;artifactName=$($folder.Name);]"
Write-Host "Published artifact $($folder.Name)..."
}
不支持从PowerShell脚本调用devops任务,您可以尝试
每个
函数来循环PublishPipelineArtifact
任务:
parameters:
- name: param
type: object
default:
- folder1
- folder2
steps:
- ${{ each p in parameters.param }}:
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifactName: '${{ p }}'
我发现“记录命令”是可能的。看 例如,此脚本将所有文件夹打包为工件:
Write-Host ("Working folder is {0}" -f $($env:SYSTEM_DEFAULTWORKINGDIRECTORY))
foreach ($folder in (Get-ChildItem -Path $env:SYSTEM_DEFAULTWORKINGDIRECTORY -Directory -ErrorAction SilentlyContinue | Select-Object Name))
{
Write-Host "Processing folder $($folder.Name)..."
$folderPath = $env:SYSTEM_DEFAULTWORKINGDIRECTORY + "\" + $folder.Name
$artifactFolder = $env:BUILD_ARTIFACTSTAGINGDIRECTORY + "\" + $folder.Name
$pathToZip = $artifactFolder + "\" + $folder.Name + ".zip"
Write-Host "Creating archive to " + $artifactFolder
New-Item -ItemType directory -Path $artifactFolder
$compress = @{
Path = $($folderPath) + "\*"
CompressionLevel = "Fastest"
DestinationPath = $pathToZip
}
Compress-Archive @compress
Write-Host "##vso[artifact.upload containerfolder=$($folder.Name);artifactname=$($folder.Name)_drop;]$pathToZip"
Write-Host "Published artifact $($folder.Name)..."
}
这正是我一直在尝试使用yaml-each循环(如@Cece-Dong的回答中所示)所做的,但是如果要发布的文件夹列表是在运行时动态生成的,则不可能在生成列表之前,对表达式中的参数进行扩展,从而导致“预期序列或映射”分析管道时出错