Reputation: 1530
I have a number of subfolders in a repository that all contain an Azure ARM template (folder name = resource group).
I'm trying to iterate each folder and then create a pipeline artifact from contents of that folder.
How do I invoke a devops task from PowerShell script? The script below gives an error saying that PublishPipelineArtifact
task is not found.
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)..."
}
Upvotes: 1
Views: 1470
Reputation: 1530
I found out that it's possible with "Logging commands". See https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md
For example this script packages all folders as artifacts:
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)..."
}
Upvotes: 1
Reputation: 31003
It's not supported to invoke a devops task from PowerShell script, you could try each
function to loop the PublishPipelineArtifact
task:
parameters:
- name: param
type: object
default:
- folder1
- folder2
steps:
- ${{ each p in parameters.param }}:
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifactName: '${{ p }}'
Upvotes: 1