DevOpsHandling/Get-DevOpsArtifacts.ps1
<#
.Synopsis Download artifacts from Azure DevOps .Description Downloads artifacts from a given project and repository and extracts them to a specified directory .Parameter devOpsOrganization Name of the organization in Azure DevOps the artifacts are contained in .Parameter devOpsProjectName Name of the project on Azure DevOps .Parameter repositoryName Name of the repository within the project. If not provided, it will be defaulted to the project name .Parameter devOpsToken Personal access token for Azure DevOps .Parameter destination Local folder the artifacts should be stored in .Example Get-DevOpsArtifacts -devOpsOrganization test -devOpsProjectName test -devOptsToken "1234567890" -destination "C:\Temp\" .Example Get-DevOpsArtifacts -devOpsOrganization test -devOpsProjectName test -repositoryName repo -devOptsToken "1234567890" -destination "C:\Temp\" #> function Get-DevOpsArtifacts { Param( [Parameter(Mandatory=$false)] [string] $devOpsOrganization = "", [Parameter(Mandatory=$false)] [string] $devOpsProjectName = "", [Parameter(Mandatory=$false)] [string] $repositoryName = "", [Parameter(Mandatory=$false)] [string] $devOpsToken = "", [Parameter(Mandatory=$true)] [string] $destination ) if ($devOpsOrganization -eq "") { $devOpsOrganization = Get-EnvironmentKeyValue -KeyName "Organization" } if ($devOpsProjectName -eq "") { $devOpsProjectName = Get-EnvironmentKeyValue -KeyName "DevOpsProject" } if ($devOpsToken -eq "") { $devOpsToken = Get-EnvironmentKeyValue -KeyName "token" } if ($null -eq $repositoryName -or $repositoryName -eq "") { $repositoryName = $devOpsProjectName } if (!(Test-Path $destination)) { New-Item -Path $destination -ItemType Directory | Out-Null } if (!(Test-Path (Join-Path $destination ".zipfolder"))) { New-Item -Path $destination -Name ".zipfolder" -ItemType Directory } Get-DevOpsArtifactsFromLastSuccessfulBuild -devOpsOrganization $devOpsOrganization -devOpsProjectName $devOpsProjectName -repositoryName $repositoryName -devOpsToken $devOpsToken -destination $destination if (Test-Path (Join-Path $destination ".zipfolder")) { Remove-Item (Join-Path $destination ".zipfolder") -Force } } Export-ModuleMember -function Get-DevOpsArtifacts |