-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathRun.ps1
More file actions
77 lines (60 loc) · 2.7 KB
/
Run.ps1
File metadata and controls
77 lines (60 loc) · 2.7 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# ensure SAS variables were passed in
if ($env:SECRET_MANAGEMENT_MODULE -eq $null)
{
Write-Verbose -Verbose "SECRET_MANAGEMENT_MODULE variable didn't get passed correctly"
return 1
}
if ($env:SECRET_MANAGEMENT_VERSION -eq $null)
{
Write-Verbose -Verbose "SECRET_MANAGEMENT_VERSION variable didn't get passed correctly"
return 1
}
if ($env:DESTINATION_ACR_NAME -eq $null)
{
Write-Verbose -Verbose "DESTINATION_ACR_NAME variable didn't get passed correctly"
return 1
}
if ($env:DESTINATION_ACR_URI -eq $null)
{
Write-Verbose -Verbose "DESTINATION_ACR_URI variable didn't get passed correctly"
return 1
}
if ($env:MI_CLIENTID -eq $null)
{
Write-Verbose -Verbose "MI_CLIENTID variable didn't get passed correctly"
return 1
}
try {
Write-Verbose -Verbose "SecretManagement: $env:SECRET_MANAGEMENT_MODULE"
Write-Verbose -Verbose "Version: $env:SECRET_MANAGEMENT_VERSION"
Write-Verbose -Verbose "acrname: $env:DESTINATION_ACR_NAME"
Write-Verbose -Verbose "acruri: $env:DESTINATION_ACR_URI"
Write-Verbose -Verbose "MI client Id: $env:MI_CLIENTID"
$secretManagementFileName = "Microsoft.PowerShell.SecretManagement.$($env:SECRET_MANAGEMENT_VERSION).nupkg"
Write-Verbose -Verbose "Download files"
Invoke-WebRequest -Uri $env:SECRET_MANAGEMENT_MODULE -OutFile $secretManagementFileName
$moduleExists = Test-Path $secretManagementFileName
Write-Verbose -Verbose "Module $secretManagementFileName exists: $moduleExists"
# Install PSResourceGet 1.1.0
Write-Verbose "Download PSResourceGet version 1.1.0"
Register-PSRepository -Name CFS -SourceLocation "https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v2" -InstallationPolicy Trusted
Install-Module -Repository CFS -Name Microsoft.PowerShell.PSResourceGet -RequiredVersion '1.1.0' -Verbose
Import-Module Microsoft.PowerShell.PSResourceGet
Get-Module
# Login to Azure CLI using Managed Identity
Write-Verbose -Verbose "Login cli using managed identity"
az login --identity --username $env:MI_CLIENTID
# Register the target ACR as a PSResourceGet repository
Write-Verbose -Verbose "Register ARC as a PSResourceGet reposirory"
Register-PSResourceRepository -Uri $env:DESTINATION_ACR_URI -Name $env:DESTINATION_ACR_NAME -Trusted -Verbose
Get-PSResourceRepository
#Publish SecretManagement to ACR
Write-Verbose -Verbose "Publish SecretManagement $secretManagementFileName to ACR $env:DESTINATION_ACR_NAME"
$prefix = "public/psresource"
Publish-PSResource -Repository $env:DESTINATION_ACR_NAME -NupkgPath $secretManagementFileName -ModulePrefix $prefix -Confirm:$false
}
catch {
$_.Exception | Format-List -Force
return 1
}
return 0