-
Notifications
You must be signed in to change notification settings - Fork 8
210 lines (201 loc) · 12.7 KB
/
reusable-prepare-dtl-env.yml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: (reusable) Prepare SharPoint test environment in DevTest Labs
on:
workflow_call:
inputs:
project-name:
required: true
type: string
description: 'Name of the project'
sharepoint-versions:
required: true
type: string
description: 'SharePoint versions to deploy'
default: '["SE"]'
skip-create-environment:
required: true
type: boolean
description: 'Set to true to skip deployment of template and jump to artifacts installation'
default: false
dtl-serviceName:
required: true
type: string
description: 'Name of the DevTest Labs service'
dtl-rgName:
required: true
type: string
description: 'Name of the resource group that contains the DevTest Labs service'
dtl-environmentName:
required: true
type: string
description: 'Name of the environment to create in the DevTest Labs service'
dtl-subscriptionId:
required: true
type: string
description: 'ID of the Azure Subscription that contains the DevTest Labs service'
azdevops-organizationName:
required: true
type: string
description: 'Name of the Azure DevOps organization where the VSTS agents are registered'
dtl-env-adminUserName:
required: true
type: string
description: 'Username of the administrator'
dtl-env-addPublicIPAddress:
required: true
type: string
description: 'Specify if each VM should have a public IP and be reachable from Internet.'
default: 'SharePointVMsOnly'
dtl-env-rdpTrafficAllowed:
required: true
type: string
description: 'Specify what incoming RDP traffic is allowed'
dtl-env-addAzureBastion:
required: true
type: boolean
description: 'Specify if Azure Bastion should be provisioned'
default: false
test-prepareSharePointVmScriptUris:
required: true
type: string
description: 'URLs of the scripts to download on the SharePoint VM to configure the claims provider'
test-claimsProviderPackageUri:
required: true
type: string
description: 'URL of the claims provider solution package to test'
unittestfiles_azure_storage_share_relative_path:
required: true
type: string
description: 'Relative path to the unit test files in the Azure storage file share'
test_registerRunner_scriptUrl:
required: true
type: string
description: 'URL of the script that adds the DTL server as a self-hosted runner on the GitHub repository'
secrets:
AZURE_CLIENT_ID:
required: true
description: 'Azure credentials'
AZURE_SUBSCRIPTION_ID:
required: true
description: 'Azure credentials'
AZURE_TENANT_ID:
required: true
description: 'Azure credentials'
ADO_PAT_REGISTERAGENT:
required: true
description: 'Personal access token to register a VSTS agent in an agent pool'
DTL_ACCOUNTSPASSWORD:
required: true
description: 'Password for the accounts in the SharePoint environment'
UNITTESTFILES_AZURE_STORAGE_CONNECTION_STRING:
required: true
description: 'Azure storage account endpoint where unit test files are located'
UNITTESTFILES_AZURE_STORAGE_SHARE_NAME:
required: true
description: 'Azure storage account file share name where unit test files are located'
GH_TOKEN_ADD_RUNNER:
required: true
description: 'GitHub token to register the DTL server as a self-hosted runner'
permissions:
id-token: write
jobs:
create-test-environment:
if: inputs.skip-create-environment != true
runs-on: ubuntu-latest
env:
# ternary 'else' is not supported, so use this workaround: https://github.com/orgs/community/discussions/25725#discussioncomment-3248924
dtl_provisionSharePointSubscription: ${{ contains(inputs.sharepoint-versions, 'SE') && 'Subscription-RTM' || 'No' }}
dtl_provisionSharePoint2019: ${{ contains(inputs.sharepoint-versions, '2019') }}
dtl_provisionSharePoint2016: ${{ contains(inputs.sharepoint-versions, '2016') }}
steps:
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Create DevTest Labs environment
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az lab environment create --lab-name ${{ inputs.dtl-serviceName }} --name ${{ inputs.dtl-environmentName }} --resource-group ${{ inputs.dtl-rgName }} --artifact-source-name "Public Repo" \
--arm-template "/subscriptions/${{ inputs.dtl-subscriptionId }}/resourceGroups/${{ inputs.dtl-rgName }}/providers/Microsoft.DevTestLab/labs/${{ inputs.dtl-serviceName }}/artifactSources/Public Environment Repo/armTemplates/SharePoint-AllVersions" \
--parameters "[ { \"name\": \"provisionSharePoint2016\", \"value\": \"${{ env.dtl_provisionSharePoint2016 }}\" }, { \"name\": \"provisionSharePoint2019\", \"value\": \"${{ env.dtl_provisionSharePoint2019 }}\" }, { \"name\": \"provisionSharePointSubscription\", \"value\": \"${{ env.dtl_provisionSharePointSubscription }}\" }, { \"name\": \"configureADFS\", \"value\": \"true\" }, { \"name\": \"enableHybridBenefitServerLicenses\", \"value\": \"true\" }, { \"name\": \"enableAutomaticUpdates\", \"value\": \"false\" }, { \"name\": \"adminUserName\", \"value\": \"${{ inputs.dtl-env-adminUserName }}\" }, { \"name\": \"adminPassword\", \"value\": \"${{ secrets.DTL_ACCOUNTSPASSWORD }}\" }, { \"name\": \"serviceAccountsPassword\", \"value\": \"${{ secrets.DTL_ACCOUNTSPASSWORD }}\" }, { \"name\": \"addPublicIPAddress\", \"value\": \"${{ inputs.dtl-env-addPublicIPAddress }}\" }, { \"name\": \"RDPTrafficAllowed\", \"value\": \"${{ inputs.dtl-env-rdpTrafficAllowed }}\" }, { \"name\": \"addAzureBastion\", \"value\": \"${{ inputs.dtl-env-addAzureBastion }}\" } ]"
#apply-artifacts-spse:
apply-artifacts:
runs-on: ubuntu-latest
needs: create-test-environment
if: |
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
#if: startsWith(inputs.dtl_provisionSharePointSubscription, 'Subscription-')
strategy:
matrix:
sharepoint_version: ${{ fromJson(inputs.sharepoint-versions) }}
# include:
# - sharepoint_version: Subscription-RTM #${{ startsWith(matrix.sharepoint_version, 'Subscription-') }}
# sps_version: 'SE'
# dtl_poolName: 'AzureCP-Tests-Subscription'
# - sharepoint_version: 2019
# sps_version: '2019'
# dtl_poolName: 'AzureCP-Tests-2019'
# - sharepoint_version: 2016
# sps_version: '2016'
# dtl_poolName: 'AzureCP-Tests-2016'
env:
vm_name: ${{ format('SP{0}', matrix.sharepoint_version) }} #${{ format('SP{0}', matrix.sps_version) }} #SPSE
dtl_poolName: ${{ format('{0}-Tests-{1}', inputs.project-name, matrix.sharepoint_version) }}
project_name: ${{ inputs.project-name }}
steps:
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Apply artifact - Register current VM as a VSTS agent in DevOps agent pools
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
artifactId="/subscriptions/${{ inputs.dtl-subscriptionId }}/resourceGroups/${{ inputs.dtl-rgName }}/providers/Microsoft.DevTestLab/labs/${{ inputs.dtl-serviceName }}/artifactSources/public repo/artifacts/windows-vsts-build-agent"
artifactApplied=$(az lab vm show --lab-name ${{ inputs.dtl-serviceName }} --resource-group ${{ inputs.dtl-rgName }} --name ${{ env.vm_name }} --expand 'properties($expand=artifacts)' --query "artifacts[?artifactId=='$artifactId' && status == 'Succeeded'].status" --output tsv)
echo $artifactApplied
if [ -z $artifactApplied ]; then
az lab vm apply-artifacts --lab-name ${{ inputs.dtl-serviceName }} --name ${{ env.vm_name }} --resource-group ${{ inputs.dtl-rgName }} \
--artifacts "[ { \"artifactId\": \"$artifactId\", \"parameters\": [ { \"name\": \"vstsAccount\", \"value\": \"${{ inputs.azdevops-organizationName }}\" }, { \"name\": \"vstsPassword\", \"value\": \"${{ secrets.ADO_PAT_REGISTERAGENT }}\" }, { \"name\": \"poolName\", \"value\": \"${{ env.dtl_poolName }}\" }, { \"name\": \"windowsLogonAccount\", \"value\": \"${{ format('{0}@contoso.local', inputs.dtl-env-adminUserName) }}\" }, { \"name\": \"windowsLogonPassword\", \"value\": \"${{ secrets.DTL_ACCOUNTSPASSWORD }}\" }, { \"name\": \"agentName\", \"value\": \"${{ env.vm_name }}\" }, { \"name\": \"agentNameSuffix\", \"value\": \"${{ format('-{0}', github.sha) }}\" }, { \"name\": \"RunAsAutoLogon\", \"value\": \"false\" }, { \"name\": \"driveLetter\", \"value\": \"C\" }, { \"name\": \"workDirectory\", \"value\": \"\" } ] } ]"
fi
- name: Apply artifact - Run a PowerShell script to download and install claims provider in current VM
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
artifactId="/subscriptions/${{ inputs.dtl-subscriptionId }}/resourceGroups/${{ inputs.dtl-rgName }}/providers/Microsoft.DevTestLab/labs/${{ inputs.dtl-serviceName }}/artifactSources/public repo/artifacts/windows-run-powershell"
artifactApplied=$(az lab vm show --lab-name ${{ inputs.dtl-serviceName }} --resource-group ${{ inputs.dtl-rgName }} --name ${{ env.vm_name }} --expand 'properties($expand=artifacts)' --query "artifacts[?artifactId=='$artifactId' && status == 'Succeeded'].status" --output tsv)
echo $artifactApplied
if [ -z $artifactApplied ]; then
# Typical value for claimsProviderPackageUri: https://github.com/Yvand/AzureCP/releases/download/nightly/EntraCP.wsp
# Typical value for unitTestsProjectUri: https://github.com/Yvand/AzureCP/releases/download/nightly/Yvand.EntraCP-unit-tests.zip
claimsProviderPackageUri=${{ inputs.test-claimsProviderPackageUri }}
projectName=${{ env.project_name }}
uriLeafPart=$(echo $claimsProviderPackageUri | grep -o '\w*\.\w*$')
unitTestsProjectUri=${claimsProviderPackageUri/$uriLeafPart/$projectName-unit-tests.zip}
echo $unitTestsProjectUri
az lab vm apply-artifacts --lab-name ${{ inputs.dtl-serviceName }} --name ${{ env.vm_name }} --resource-group ${{ inputs.dtl-rgName }} \
--artifacts "[ { \"artifactId\": \"$artifactId\", \"parameters\": [ { \"name\": \"scriptFileUris\", \"value\": \" ${{ inputs.test-prepareSharePointVmScriptUris }} \" }, { \"name\": \"scriptToRun\", \"value\": \"ConfigureLab.ps1\" }, { \"name\": \"scriptArguments\", \"value\": \"-claimsProviderPackageUri '$claimsProviderPackageUri' -claimsProviderUnitTestsUri '$unitTestsProjectUri' -spTrustName 'contoso.local' -adminUserName '${{ format('contoso\{0}', inputs.dtl-env-adminUserName) }}' -adminPassword '${{ secrets.DTL_ACCOUNTSPASSWORD }}' -storageAccountEndpoint '${{ secrets.UNITTESTFILES_AZURE_STORAGE_CONNECTION_STRING }}' -storageAccountShareName '${{ secrets.UNITTESTFILES_AZURE_STORAGE_SHARE_NAME }}' -storageAccountSourceRelativePath '${{ inputs.unittestfiles_azure_storage_share_relative_path }}'\" } ] } ]"
fi
- name: Apply artifact - Run a PowerShell script to add self-hosted runner to the repository
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
artifactId="/subscriptions/${{ inputs.dtl-subscriptionId }}/resourceGroups/${{ inputs.dtl-rgName }}/providers/Microsoft.DevTestLab/labs/${{ inputs.dtl-serviceName }}/artifactSources/public repo/artifacts/windows-run-powershell"
gh_token=${{ secrets.GH_TOKEN_ADD_RUNNER }}
gh_repo_owner_name=${{ github.repository }}
gh_repo_url="https://github.com/$gh_repo_owner_name"
scriptFileUris=${{ inputs.test_registerRunner_scriptUrl }}
scriptToRun="Add-RunnerToRepo.ps1"
echo $gh_repo_url
az lab vm apply-artifacts --lab-name ${{ inputs.dtl-serviceName }} --name ${{ env.vm_name }} --resource-group ${{ inputs.dtl-rgName }} \
--artifacts "[ { \"artifactId\": \"$artifactId\", \"parameters\": [ { \"name\": \"scriptFileUris\", \"value\": \"$scriptFileUris\" }, { \"name\": \"scriptToRun\", \"value\": \"Add-RunnerToRepo.ps1\" }, { \"name\": \"scriptArguments\", \"value\": \"-gh_repo_url '$gh_repo_url' -gh_token '$gh_token' \" } ] } ]"