-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathRun.ps1
More file actions
85 lines (68 loc) · 2.83 KB
/
Run.ps1
File metadata and controls
85 lines (68 loc) · 2.83 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
78
79
80
81
82
83
84
85
# ensure variables were passed in
if ($env:NUPKG_PATH -eq $null)
{
Write-Verbose -Verbose "NUPKG_PATH variable didn't get set properly"
return 1
}
if ($env:PSRESOURCE_NAME -eq $null)
{
Write-Verbose -Verbose "PSRESOURCE_NAME variable didn't get set properly"
return 1
}
if ($env:PSRESOURCE_VERSION -eq $null)
{
Write-Verbose -Verbose "PSRESOURCE_VERSION variable didn't get set properly"
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 ".nupkg file path: $env:NUPKG_PATH"
Write-Verbose -Verbose "psresource name: $env:PSRESOURCE_NAME"
Write-Verbose -Verbose "psresource version: $env:PSRESOURCE_VERSION"
Write-Verbose -Verbose "ACR name: $env:DESTINATION_ACR_NAME"
Write-Verbose -Verbose "ACR uri: $env:DESTINATION_ACR_URI"
Write-Verbose -Verbose "MI client Id: $env:MI_CLIENTID"
$nupkgFileName = "$($env:PSRESOURCE_NAME).$($env:PSRESOURCE_VERSION).nupkg"
Write-Verbose -Verbose "Download file"
Invoke-WebRequest -Uri $env:NUPKG_PATH -OutFile $nupkgFileName
# 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' -AllowPrerelease -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 --client-id $env:MI_CLIENTID
# Register the target ACR as a PSResourceGet repository
Write-Verbose -Verbose "Register ACR as a PSResourceGet reposirory"
Register-PSResourceRepository -Uri $env:DESTINATION_ACR_URI -Name $env:DESTINATION_ACR_NAME -Trusted -Verbose
Get-PSResourceRepository
# Publish module to ACR
Write-Verbose -Verbose "Publish $env:PSRESOURCE_NAME from file $nupkgFileName to ACR $env:DESTINATION_ACR_NAME"
# unlisted
$prefix = "unlisted/psresource"
Publish-PSResource -NupkgPath $nupkgFileName -Repository $env:DESTINATION_ACR_NAME -ModulePrefix $prefix -Confirm:$false
# public
$prefix = "public/psresource"
Publish-PSResource -NupkgPath $nupkgFileName -Repository $env:DESTINATION_ACR_NAME -ModulePrefix $prefix -Confirm:$false
}
catch {
$_.Exception | Format-List -Force
return 1
}
return 0