-
Notifications
You must be signed in to change notification settings - Fork 152
/
build.ps1
43 lines (34 loc) · 1.47 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
param(
[Parameter(Mandatory=$true)]$mgId,
[Parameter(Mandatory=$true)]$BlueprintFolder,
[Parameter(Mandatory=$true)]$blueprintName,
[Parameter(Mandatory=$true)]$spnId,
[Parameter(Mandatory=$true)]$spnPass,
[Parameter(Mandatory=$true)]$tenantId
)
# Output powershell version for debugging purposes and is probably generally good to know
$PSVersionTable.PSVersion # Assuming powershell core (6)
Write-Host "Installing Az module"
Install-Module -Name Az.Blueprint -AllowClobber # todo - check installation status
Write-Host "Successfully installed Az.Blueprint module"
Write-Host "Start login with SPN"
$pass = ConvertTo-SecureString $spnPass -AsPlainText -Force
$cred = New-Object -TypeName pscredential -ArgumentList $spnId, $pass
Login-AzAccount -Credential $cred -ServicePrincipal -TenantId $tenantId
Write-Host "Successfully logged in with SPN"
Write-Host "Azure context:"
Get-AzContext
Write-Host "Start Blueprint import"
Import-AzBlueprintWithArtifact -Name $blueprintName -ManagementGroupId $mgId -InputPath $BlueprintFolder -Force
# success
if ($?) {
Write-Host "Imported successfully"
$date = Get-Date -UFormat %Y%m%d.%H%M%S
$genVersion = "$date.TEST" # todo - use the version from DevOps
$importedBp = Get-AzBlueprint -ManagementGroupId $mgId -Name $blueprintName
Publish-AzBlueprint -Blueprint $importedBp -Version $genVersion
# TODO - Clean up old test version(s)
} else {
throw "Failed to import successfully"
exit 1
}