pf-AzPipelines.ps1
# https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md # https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=powershell # https://medium.com/microsoftazure/how-to-pass-variables-in-azure-pipelines-yaml-tasks-5c81c5d31763 function Invoke-AzPipeline_Command { Param( $command, $value ) $argList = Get-CmdUnboundArgs $MyInvocation.UnboundArguments $strItems = @() $strItems += foreach ($argItem in $argList.GetEnumerator() ) { if ($argItem.Key -eq "params") { continue } $argValue = (-not $argItem.Value ) ? 'true' : $argItem.Value -join ',' "" + $argItem.Key + "=" + $argValue } $paramStr = $strItems -join ' ' Write-Host "##vso[$command $paramStr]$value" } function Invoke-AzPipeline_Command:::Example { Invoke-AzPipeline_Command -command 'task.setvariable' -Name "VarName" -value "varValue" ` -isReadonly -isOutput } function Write-AzPipeline_log ($message, $activityID = [Guid]::NewGuid(), $name) { $name = $name ?? "Build Log" Invoke-AzPipeline_Command -command 'task.logdetail' -value $message ` -id $activityID -name $name -type 'build' -order 1 Write-Host $message } function Write-AzPipeline_log:::Example { Write-AzPipeline_log -message 'LogMessage' } function Set-AzPipeline_Variable { param( [Parameter(ValueFromPipelineByPropertyName=$true)] [Alias('Key')] $Name, [Parameter(ValueFromPipelineByPropertyName=$true)] $value, [switch]$isReadonly, [switch]$isOutput ) process { $additional = [Ordered]@{} if($isReadonly) { $additional.Add('isReadonly','true') } if($isOutput) { $additional.Add('isOutput','true') } Invoke-AzPipeline_Command @additional -command "task.setvariable" -variable $Name -value $value -params $additional } } function Set-AzPipeline_Variable:::example { Set-AzPipeline_Variable -Name "VarName" -value "varValue" -isReadonly -isOutput } function Publish-AzPipeline_File ($Path) { Invoke-AzPipeline_Command -command 'task.uploadfile' -value $Path } function Set-AzPipeline_BuildNumber ($value) { Invoke-AzPipeline_Command -command 'build.updatebuildnumber' -value $value } |