-
Notifications
You must be signed in to change notification settings - Fork 44
/
azure-pipelines-PR.yaml
72 lines (63 loc) · 2.95 KB
/
azure-pipelines-PR.yaml
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
trigger: # don't trigger outside PRs
- none
pr: # Trigger the pipeline only for PRs targeting master branch
- master
variables:
imageRepository: 'collab'
location: 'canadacentral'
RGtemplateFile: '.bicep/PR/test-instance-setup.bicep'
commentStringGCcollab: 'GCcollab test instance up at:' # String used for PR comment to provide link to review site
commentStringGCconnex: 'GCconnex test instance up at:'
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: setup
displayName: build and set up review site
steps:
- task: Docker@2
displayName: Build and Push Container image to ACR
inputs:
command: 'buildAndPush'
containerRegistry: $(acrServiceConnection)
repository: '$(imageRepository)_pr-$(System.PullRequest.PullRequestNumber)' # per-PR repos for easier cleanup
tags: '$(Build.SourceVersion)'
- task: AzureCLI@2
displayName: set up review / test instance using bicep
condition: succeeded()
inputs:
azureSubscription: $(azSubServiceConnection)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
az deployment sub create --location $LOCATION --template-file $TEMPLATE_FILE \
--parameters prNumber=$PR dbServerName=$DBSERVERNAME dbServerRG=$DBRG containerTag=$TAG dbServerPass=$(REVIEW_DB_SERVER_PASS) \
subnetID=$SUBNET_ID planID=$PLAN_ID acrName=$ACR_NAME siteType=gccollab
az deployment sub create --location $LOCATION --template-file $TEMPLATE_FILE \
--parameters prNumber=$PR dbServerName=$DBSERVERNAME dbServerRG=$DBRG containerTag=$TAG dbServerPass=$(REVIEW_DB_SERVER_PASS) \
subnetID=$SUBNET_ID planID=$PLAN_ID acrName=$ACR_NAME siteType=gcconnex
env:
DBRG: $(db_resource_group)
DBSERVERNAME: $(review_db_server_name)
TAG: $(Build.SourceVersion)
PR: $(System.PullRequest.PullRequestNumber)
SUBNET_ID: $(review_subnet_ID)
PLAN_ID: $(review_plan_ID)
LOCATION: $(location)
TEMPLATE_FILE: $(RGtemplateFile)
ACR_NAME: $(acrName)
- bash: |
TEST=$(curl -L https://api.github.com/repos/gctools-outilsgc/gcconnex/issues/$PR/comments | grep -c "${{ variables.commentStringGCcollab }}")
echo "##vso[task.setvariable variable=commentExists]$TEST"
echo "Comments found about the test instance already in the PR: $TEST"
displayName: Check for comment in PR
env:
PR: $(System.PullRequest.PullRequestNumber)
- task: GitHubComment@0
inputs:
gitHubConnection: $(github_connection)
repositoryName: $(Build.Repository.Name)
id: $(System.PullRequest.PullRequestNumber)
comment: '$(commentStringGCcollab) https://gccollab-dev-pr-$(System.PullRequest.PullRequestNumber).azurewebsites.net/ <br />
$(commentStringGCconnex) https://gcconnex-dev-pr-$(System.PullRequest.PullRequestNumber).azurewebsites.net/ '
condition: and(succeeded(), eq(variables['commentExists'], '0'))
displayName: Post a comment to PR with link to review site