@@ -203,6 +203,9 @@ Export-ModuleMember -Function Get-AzDevOpsPipelineYaml
203203 . PARAMETER OutputPath
204204 Output path for YAML file
205205
206+ . PARAMETER PassThru
207+ Pass the YAML definition to the pipeline object
208+
206209 . EXAMPLE
207210 Export-AzDevOpsPipelineYaml -Project $Project -PipelineId $PipelineId -OutputPath $OutputPath
208211#>
@@ -218,9 +221,12 @@ function Export-AzDevOpsPipelineYaml {
218221 [Parameter (Mandatory )]
219222 [string ]
220223 $PipelineName ,
221- [Parameter (Mandatory )]
224+ [Parameter (ParameterSetName = ' YamlFile ' )]
222225 [string ]
223- $OutputPath
226+ $OutputPath ,
227+ [Parameter (ParameterSetName = ' PassThru' )]
228+ [switch ]
229+ $PassThru
224230 )
225231 if ($null -eq $script :connection ) {
226232 throw " Not connected to Azure DevOps. Run Connect-AzDevOps first"
@@ -236,8 +242,12 @@ function Export-AzDevOpsPipelineYaml {
236242 return $null
237243 } else {
238244 $yaml += $yamlTemp }
239- Write-Verbose " Exporting YAML definition to $OutputPath \$PipelineName .yaml"
240- $yaml | Out-File " $OutputPath \$PipelineName .yaml"
245+ if ($PassThru ) {
246+ Write-Output $yaml
247+ } else {
248+ Write-Verbose " Exporting YAML definition to $OutputPath \$PipelineName .yaml"
249+ $yaml | Out-File " $OutputPath \$PipelineName .yaml"
250+ }
241251}
242252Export-ModuleMember - Function Export-AzDevOpsPipelineYaml
243253# End of Function Export-AzDevOpsPipelineYaml
@@ -256,6 +266,9 @@ Export-ModuleMember -Function Export-AzDevOpsPipelineYaml
256266 . PARAMETER OutputPath
257267 Output path for JSON files
258268
269+ . PARAMETER PassThru
270+ Pass the pipeline object to the pipeline object instead of exporting to a file
271+
259272 . EXAMPLE
260273 Export-AzDevOpsPipelines -Project $Project -OutputPath $OutputPath
261274#>
@@ -265,9 +278,12 @@ function Export-AzDevOpsPipelines {
265278 [Parameter (Mandatory )]
266279 [string ]
267280 $Project ,
268- [Parameter (Mandatory )]
281+ [Parameter (ParameterSetName = ' JsonFile ' )]
269282 [string ]
270- $OutputPath
283+ $OutputPath ,
284+ [Parameter (ParameterSetName = ' PassThru' )]
285+ [switch ]
286+ $PassThru
271287 )
272288 if ($null -eq $script :connection ) {
273289 throw " Not connected to Azure DevOps. Run Connect-AzDevOps first"
@@ -290,16 +306,24 @@ function Export-AzDevOpsPipelines {
290306 } else {
291307 Write-Verbose " Token Type is set to ReadOnly, no pipeline ACLs will be returned"
292308 }
293- Write-Verbose " Exporting pipeline $ ( $pipeline.name ) to JSON file"
294- Write-Verbose " Exporting pipeline as JSON file to $OutputPath \$ ( $pipeline.name ) .ado.pl.json"
295- $pipeline | ConvertTo-Json - Depth 100 | Out-File " $OutputPath \$ ( $pipeline.name ) .ado.pl.json"
296- if ($pipeline.configuration.type -eq ' yaml' -and $pipeline.configuration.repository.type -eq ' azureReposGit' ) {
297- Write-Verbose " Pipeline $ ( $pipeline.name ) is a YAML pipeline"
298- Write-Verbose " Getting YAML definition for pipeline $ ( $pipeline.name ) "
299- Export-AzDevOpsPipelineYaml - Project $Project - PipelineId $pipeline.id - PipelineName $pipeline.name - OutputPath $OutputPath
300-
309+ If ($PassThru ) {
310+ if ($pipeline.configuration.type -eq ' yaml' -and $pipeline.configuration.repository.type -eq ' azureReposGit' ) {
311+ Write-Verbose " Pipeline $ ( $pipeline.name ) is a YAML pipeline"
312+ Write-Verbose " Getting YAML definition for pipeline $ ( $pipeline.name ) "
313+ Export-AzDevOpsPipelineYaml - Project $Project - PipelineId $pipeline.id - PipelineName $pipeline.name - PassThru
314+ }
315+ Write-Output $pipeline
316+ } else {
317+ Write-Verbose " Exporting pipeline $ ( $pipeline.name ) to JSON file"
318+ Write-Verbose " Exporting pipeline as JSON file to $OutputPath \$ ( $pipeline.name ) .ado.pl.json"
319+ $pipeline | ConvertTo-Json - Depth 100 | Out-File " $OutputPath \$ ( $pipeline.name ) .ado.pl.json"
320+ if ($pipeline.configuration.type -eq ' yaml' -and $pipeline.configuration.repository.type -eq ' azureReposGit' ) {
321+ Write-Verbose " Pipeline $ ( $pipeline.name ) is a YAML pipeline"
322+ Write-Verbose " Getting YAML definition for pipeline $ ( $pipeline.name ) "
323+
324+ Export-AzDevOpsPipelineYaml - Project $Project - PipelineId $pipeline.id - PipelineName $pipeline.name - OutputPath $OutputPath
325+ }
301326 }
302-
303327 }
304328}
305329Export-ModuleMember - Function Export-AzDevOpsPipelines
0 commit comments