Module/DevOps/New-BCSDevOpsProject.ps1
<#
.SYNOPSIS Create a new Azure DevOps Project .DESCRIPTION ... .PARAMETER organisation DevOps organisation where the project will be created. .PARAMETER projectName Name of the project to create .PARAMETER licenseFile path to licensfile .PARAMETER password DevOps build container default password .PARAMETER storageConnectionString Connection string to Azure Blob storage .PARAMETER storageContainerName Name of azure blob storage .EXAMPLE New-BCSDevOpsProject -$organisation 'MyOrg' -projectName 'MyProject' -SourcePat {PersonalAccessToken} .NOTES Author: Mathias Stjernfelt Website: http://www.brightcom.se #> function New-BCSDevOpsProject { [CmdletBinding(SupportsShouldProcess)] Param ( [Parameter(Mandatory = $false)] [string]$organisation = 'BrightComSolutions', [Parameter(Mandatory = $true)] [string]$projectName, [Parameter(Mandatory = $false)] [string]$licenseFile = 'https://brightcomdevops.blob.core.windows.net/devops/5538404.flf', [Parameter(Mandatory = $false)] [securestring]$password, [Parameter(Mandatory = $false)] [string]$storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=brightcomdevops;AccountKey=UfD/OHNSHxXySmbjQdH1ntXdfz+bd9oQ1upO72NRLpZA4w1VEnRAPPanVdH/5zO1y2DpuqnVfWNoRXP8HpJQ/w==", [Parameter(Mandatory = $false)] [string]$storageContainerName = "devops", [Parameter(Mandatory = $true)] [string]$sourcePat ) try { $projectName = "Horse Online" $sourcePat = "s3cdy4oyp2rfwfttdfdjru3x2t46ubpkyptlhwxbfetfyuk662ka" $organisation = 'BrightComSolutions' $variableGroupName = "BusinessCentral"; $fullOrgUrl = "https://dev.azure.com/$organisation" $sourcePat | az devops login --org $fullOrgUrl Write-host "Logged in to '$fullOrgUrl'" $project = az devops project show --project $projectName --org $fullOrgUrl | convertfrom-json if ([Object]::ReferenceEquals($project, $null)) { if ($PSCmdlet.ShouldProcess($projectName)) { $project = az devops project create --name $projectName --org $fullOrgUrl | convertfrom-json Write-host ("Project {0} was successfully creted in organisation {1}." -f $project.name, $organisation) } } else { Write-host ("Project {0} already exists in organisation {1}, aborting." -f $project.name, $organisation) -ForegroundColor Red exit; } Write-host ("Setting up Variable group {0} " -f $variableGroupName) $group = az pipelines variable-group create --name $variableGroupName --project $projectName --org $fullOrgUrl --variable "LicenseFile=$licensefile" | ConvertFrom-json Write-host " - Adding secret variable LicenseFile" $variable = az pipelines variable-group variable update --group-id $group.id --name "LicenseFile" --project $projectName --org $fullOrgUrl --secret true --value $licenseFile Write-host " - Adding secret variable Password" $variable = az pipelines variable-group variable create --group-id $group.id --name "Password" --project $projectName --org $fullOrgUrl --secret true --value 'P@ssw0rd' Write-host " - Adding secret variable StorageConnectionString" $variable = az pipelines variable-group variable create --group-id $group.id --name "StorageConnectionString" --project $projectName --org $fullOrgUrl --secret true --value $storageConnectionString Write-host " - Adding secret variable StorageContainerName" $variable = az pipelines variable-group variable create --group-id $group.id --name "StorageContainerName" --project $projectName --org $fullOrgUrl --secret true --value $storageContainerName } catch { throw "An error occured: $_.Exception"; } finally { az DevOps logout } } Export-ModuleMember -Function New-BCSDevOpsProject |