Skip to content

Commit 390bb64

Browse files
committed
Create OneBranch pipeline to release PSResourceGet to MAR
1 parent 097cfc2 commit 390bb64

12 files changed

+636
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"Settings": {
3+
"tenantid": "00000000-0000-0000-0000-000000000000",
4+
"environment": "Prod",
5+
"subscription": {
6+
"backFilledSubscriptionId": "00000000-0000-0000-0000-000000000000",
7+
"backFilledSubscriptionName": "default",
8+
"subscriptionkey": "SubKey-Prod-PSResourceGetMAR"
9+
},
10+
"azureResourceGroup": "default"
11+
}
12+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"$schema": "https://ev2schema.azure.net/schemas/2020-01-01/rolloutParameters.json",
3+
"contentVersion": "1.0.0.0",
4+
"shellExtensions": [
5+
{
6+
"name": "Run",
7+
"type": "Run",
8+
"properties": {
9+
"maxExecutionTime": "PT2H"
10+
},
11+
"package": {
12+
"reference": {
13+
"path": "Shell/Run.tar"
14+
}
15+
},
16+
"launch": {
17+
"command": [
18+
"/bin/bash",
19+
"-c",
20+
"pwsh ./Run/Run.ps1"
21+
],
22+
"environmentVariables": [
23+
{
24+
"name": "NUPKG_PATH",
25+
"reference":
26+
{
27+
"path": "default"
28+
}
29+
},
30+
{
31+
"name": "PSRESOURCE_NAME",
32+
"value": "default"
33+
},
34+
{
35+
"name": "PSRESOURCE_VERSION",
36+
"value": "default"
37+
},
38+
{
39+
"name": "DESTINATION_ACR_NAME",
40+
"value": "default"
41+
},
42+
{
43+
"name": "DESTINATION_ACR_URI",
44+
"value": "default"
45+
},
46+
{
47+
"name": "MI_CLIENTID",
48+
"value": "default"
49+
}
50+
],
51+
"identity": {
52+
"type": "userAssigned",
53+
"userAssignedIdentities": [
54+
"default"
55+
]
56+
}
57+
}
58+
}
59+
]
60+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://ev2schema.azure.net/schemas/2020-01-01/rolloutParameters.json",
3+
"contentVersion": "1.0.0.0",
4+
"subscriptions": [
5+
{
6+
"name": "SubscriptionProvisioning",
7+
"displayName": "__BACKFILLED_SUBSCRIPTION_NAME__",
8+
"backfilledSubscriptionId": "__BACKFILLED_SUBSCRIPTION_ID__"
9+
}
10+
]
11+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"$schema": "https://ev2schema.azure.net/schemas/2020-04-01/RegionAgnosticRolloutSpecification.json",
3+
"contentVersion": "1.0.0.0",
4+
"rolloutMetadata": {
5+
"serviceModelPath": "ServiceModel.json",
6+
"ScopeBindingsPath": "ScopeBindings.json",
7+
"name": "Microsoft.Azure.PSCore.PSResourceGet",
8+
"rolloutType": "Major",
9+
"buildSource": {
10+
"parameters": {
11+
"versionFile": "buildver.txt"
12+
}
13+
},
14+
"configuration": {
15+
"serviceGroupScope": {
16+
"specPath": "ConfigServiceGroup.json"
17+
}
18+
},
19+
"Notification": {
20+
"Email": {
21+
"To": "default"
22+
}
23+
}
24+
},
25+
"orchestratedSteps": [
26+
{
27+
"name": "PSResourceGetMARRelease",
28+
"targetType": "ServiceResourceDefinition",
29+
"targetName": "PSResourceGetMARReleaseShell",
30+
"actions": ["Shell/Run"]
31+
}
32+
]
33+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"$schema": "https://ev2schema.azure.net/schemas/2020-01-01/scopeBindings.json",
3+
"contentVersion": "0.0.0.1",
4+
"scopeBindings": [
5+
{
6+
"scopeTagName": "Global",
7+
"bindings": [
8+
{
9+
"find": "__SUBSCRIPTION_ID__",
10+
"replaceWith": "$azureSubscriptionId()"
11+
},
12+
{
13+
"find": "__RESOURCE_GROUP__",
14+
"replaceWith": "$azureResourceGroup()"
15+
},
16+
{
17+
"find": "__BUILD_VERSION__",
18+
"replaceWith": "$buildVersion()"
19+
}
20+
]
21+
},
22+
{
23+
"scopeTagName": "scope.tag.subscriptionprovisioning",
24+
"bindings": [
25+
{
26+
"find": "__BACKFILLED_SUBSCRIPTION_NAME__",
27+
"replaceWith": "$config(subscription.backFilledSubscriptionName)"
28+
},
29+
{
30+
"find": "__BACKFILLED_SUBSCRIPTION_ID__",
31+
"replaceWith": "$config(subscription.backFilledSubscriptionId)"
32+
}
33+
]
34+
}
35+
]
36+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "Microsoft.Azure.PSCore.PSResourceGet",
3+
"description": "PSResourceGet Publish to MAR",
4+
"ownerGroupObjectId": "00000000-0000-0000-0000-000000000000",
5+
"ownerGroupContactEmail": "default",
6+
"contentVersion": "1.0.0.0"
7+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"$schema": "https://ev2schema.azure.net/schemas/2020-04-01/regionAgnosticServiceModel.json",
3+
"contentVersion": "1.0.0.0",
4+
"serviceMetadata": {
5+
"serviceIdentifier": "00000000-0000-0000-0000-000000000000",
6+
"serviceGroup": "Microsoft.Azure.PSCore.PSResourceGet",
7+
"serviceSpecificationPath": "ServiceSpecification.json",
8+
"serviceGroupSpecificationPath": "ServiceGroupSpecification.json",
9+
"environment": "$config(environment)",
10+
"displayName":"PSResourceGet-Ev2Release-MAR",
11+
"tenantId":"$config(tenantid)"
12+
},
13+
"subscriptionProvisioning": {
14+
"rolloutParametersPath": "Parameters\\subscriptionProvisioning.rolloutParameters.json",
15+
"scopeTags": [
16+
{
17+
"name": "scope.tag.subscriptionprovisioning"
18+
}
19+
]
20+
},
21+
"serviceResourceGroupDefinitions": [
22+
{
23+
"name": "OneBranch-PSResourceGet-RGDef",
24+
"azureResourceGroupName": "$config(azureResourceGroup)",
25+
"subscriptionKey": "$config(subscription.subscriptionkey)",
26+
"serviceResourceDefinitions": [
27+
{
28+
"name": "PSResourceGetMARReleaseShell",
29+
"composedOf": {
30+
"extension": {
31+
"rolloutParametersPath": "PSResourceGetReleaseMAR.Rollout.json",
32+
"shell": [
33+
{
34+
"type": "Run",
35+
"properties": {
36+
"imageName": "adm-azurelinux-30-l",
37+
"imageVersion": "v2"
38+
}
39+
}
40+
]
41+
}
42+
},
43+
"scopeTags": [
44+
{
45+
"name": "Global"
46+
}
47+
]
48+
}
49+
]
50+
}
51+
]
52+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://ev2schema.azure.net/schemas/2020-01-01/serviceSpecification.json",
3+
"providerType": "ServiceTree",
4+
"identifier": "00000000-0000-0000-0000-000000000000",
5+
"description": "PowerShell Core service for deployments.",
6+
"ownerGroupContactEmail": "default",
7+
"policyCheckEnabled": true,
8+
"contentVersion": "1.0.0.0"
9+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# ensure variables were passed in
2+
if ($env:NUPKG_PATH -eq $null)
3+
{
4+
Write-Verbose -Verbose "NUPKG_PATH variable didn't get set properly"
5+
return 1
6+
}
7+
8+
if ($env:PSRESOURCE_NAME -eq $null)
9+
{
10+
Write-Verbose -Verbose "PSRESOURCE_NAME variable didn't get set properly"
11+
return 1
12+
}
13+
14+
if ($env:PSRESOURCE_VERSION -eq $null)
15+
{
16+
Write-Verbose -Verbose "PSRESOURCE_VERSION variable didn't get set properly"
17+
return 1
18+
}
19+
20+
if ($env:DESTINATION_ACR_NAME -eq $null)
21+
{
22+
Write-Verbose -Verbose "DESTINATION_ACR_NAME variable didn't get passed correctly"
23+
return 1
24+
}
25+
26+
if ($env:DESTINATION_ACR_URI -eq $null)
27+
{
28+
Write-Verbose -Verbose "DESTINATION_ACR_URI variable didn't get passed correctly"
29+
return 1
30+
}
31+
32+
if ($env:MI_CLIENTID -eq $null)
33+
{
34+
Write-Verbose -Verbose "MI_CLIENTID variable didn't get passed correctly"
35+
return 1
36+
}
37+
38+
try {
39+
Write-Verbose -Verbose ".nupkg file path: $env:NUPKG_PATH"
40+
Write-Verbose -Verbose "psresource name: $env:PSRESOURCE_NAME"
41+
Write-Verbose -Verbose "psresource version: $env:PSRESOURCE_VERSION"
42+
Write-Verbose -Verbose "ACR name: $env:DESTINATION_ACR_NAME"
43+
Write-Verbose -Verbose "ACR uri: $env:DESTINATION_ACR_URI"
44+
Write-Verbose -Verbose "MI client Id: $env:MI_CLIENTID"
45+
46+
$nupkgFileName = "$($env:PSRESOURCE_NAME).$($env:PSRESOURCE_VERSION).nupkg"
47+
Write-Verbose -Verbose "Download file"
48+
Invoke-WebRequest -Uri $env:NUPKG_PATH -OutFile $nupkgFileName
49+
50+
# Install PSResourceGet 1.1.0
51+
Write-Verbose "Download PSResourceGet version 1.1.0"
52+
Register-PSRepository -Name CFS -SourceLocation "https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v2" -InstallationPolicy Trusted
53+
Install-Module -Repository CFS -Name Microsoft.PowerShell.PSResourceGet -RequiredVersion '1.1.0' -AllowPrerelease -Verbose
54+
Import-Module Microsoft.PowerShell.PSResourceGet
55+
Get-Module
56+
57+
# Login to Azure CLI using Managed Identity
58+
Write-Verbose -Verbose "Login cli using managed identity"
59+
az login --identity --client-id $env:MI_CLIENTID
60+
61+
# Register the target ACR as a PSResourceGet repository
62+
Write-Verbose -Verbose "Register ACR as a PSResourceGet reposirory"
63+
Register-PSResourceRepository -Uri $env:DESTINATION_ACR_URI -Name $env:DESTINATION_ACR_NAME -Trusted -Verbose
64+
65+
Get-PSResourceRepository
66+
67+
# Publish module to ACR
68+
Write-Verbose -Verbose "Publish $env:PSRESOURCE_NAME from file $nupkgFileName to ACR $env:DESTINATION_ACR_NAME"
69+
70+
# unlisted
71+
$prefix = "unlisted/psresource"
72+
Publish-PSResource -NupkgPath $nupkgFileName -Repository $env:DESTINATION_ACR_NAME -ModulePrefix $prefix -Confirm:$false
73+
74+
# public
75+
$prefix = "public/psresource"
76+
77+
Publish-PSResource -NupkgPath $nupkgFileName -Repository $env:DESTINATION_ACR_NAME -ModulePrefix $prefix -Confirm:$false
78+
}
79+
catch {
80+
$_.Exception | Format-List -Force
81+
82+
return 1
83+
}
84+
85+
return 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.2.0.101

0 commit comments

Comments
 (0)