-
Notifications
You must be signed in to change notification settings - Fork 2
/
azure-pipelines.yml
131 lines (124 loc) · 6.12 KB
/
azure-pipelines.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
variables:
- group: demo-vm-deploy
trigger:
- master
- andrei
- stefan
stages:
- stage: Build
displayName: Build image
jobs:
- job: demo_image_build
pool:
vmImage: 'ubuntu-18.04'
container:
image: $(containerRegistry).azurecr.io/$(dockerBuildRepositoryName):latest
endpoint: dsfAcrConnection
timeoutInMinutes: 360
steps:
- bash: 'sudo chown -R "$(whoami):" .'
displayName: 'Changing the owner of /ansible folder to AzureDevops user'
failOnStderr: true
- bash: 'packer build -on-error=abort -force packer/packer-build.json'
displayName: 'Run Packer with Ansible build for alias '
failOnStderr: true
timeoutInMinutes: 360
env:
SUBSCRIPTION_ID: '$(testSubscriptionId)'
PACKER_CLIENT_ID: '$(packerClientId)'
PACKER_CLIENT_SECRET: '$(packerClientSecret)'
RESOURCE_GROUP_NAME: '$(testResourceGroupName)'
GIT_REPO_SOURCE: '$(uipathDemoGitRepo)'
GIT_TOKEN: $(githubToken)
SHARED_IMAGE_NAME: '$(managedImageName)'
MONGO_DB_CONNECTION_STRING: '$mongoDBConnectionString)'
PROJECT_NAME: '$(projectName)'
OWNER_EMAIL: '$(ownerEmail)'
PACKER_VM_SIZE: '$(packerVMSize)'
PACKER_BASE_IMAGE: '$(packerBaseImage)'
PACKER_BASE_SKU: '$(packerBaseSKU)'
PACKER_USERNAME: '$(packerUsername)'
BLOB_CONN_STRING: '$(blobConnectionString)'
- task: CopyFiles@2
inputs:
targetFolder: $(Build.ArtifactStagingDirectory)
contents: '$(Build.SourcesDirectory)/manifest.json'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)
artifactName: manifest
- stage: DeployDevUat
displayName: Deploy dev branch to UAT
dependsOn: Build
condition: and( succeeded(), not( eq( variables['Build.Reason'], 'PullRequest')))
jobs:
- deployment: deployDevUat
environment: uat
pool:
vmImage: 'ubuntu-16.04'
timeoutInMinutes: 360
strategy:
runOnce:
deploy:
steps:
- task: AzureCLI@2
displayName: publish image to SIG and replicate
inputs:
azureSubscription: $(testAzureConnection)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
MANAGED_IMAGE="/subscriptions/$(testSubscriptionId)/resourceGroups/$(testResourceGroupName)/providers/Microsoft.Compute/images/$(managedImageName)"
az sig image-version create -g $(testResourceGroupName) --gallery-name $(testSharedImageGalleryName) --gallery-image-definition $(managedImageName) --gallery-image-version 0.0.$(Build.BuildId) --managed-image $MANAGED_IMAGE --storage-account-type standard_zrs
- stage: DeployPrUat
displayName: Deploy pull request to UAT
dependsOn: Build
condition: and( succeeded(),eq( variables['system.pullRequest.targetBranch'], 'master'), eq( variables['Build.Reason'], 'PullRequest'))
jobs:
- deployment: deployPrUat
environment: uat
pool:
vmImage: 'ubuntu-16.04'
timeoutInMinutes: 360
strategy:
runOnce:
deploy:
steps:
- task: AzureCLI@2
displayName: publish image to SIG and replicate
inputs:
azureSubscription: $(testAzureConnection)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
MANAGED_IMAGE="/subscriptions/$(testSubscriptionId)/resourceGroups/$(testResourceGroupName)/providers/Microsoft.Compute/images/$(managedImageName)"
az sig image-version create -g $(testResourceGroupName) --gallery-name $(testSharedImageGalleryName) --gallery-image-definition $(managedImageName) --gallery-image-version 0.0.$(Build.BuildId) --managed-image $MANAGED_IMAGE --storage-account-type standard_zrs
- stage: DeployProd
displayName: Deploy to Prod
dependsOn: DeployPrUat
condition: and( succeeded(),eq( variables['system.pullRequest.targetBranch'], 'master'), eq( variables['Build.Reason'], 'PullRequest'))
jobs:
- deployment: deployProd
environment: prod
pool:
vmImage: 'ubuntu-16.04'
timeoutInMinutes: 360
strategy:
runOnce:
deploy:
steps:
- task: AzureCLI@2
displayName: publish image to SIG and replicate
inputs:
azureSubscription: $(prodAzureConnection)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
SOURCE_MANAGED_IMAGE="/subscriptions/$(testSubscriptionId)/resourceGroups/$(testResourceGroupName)/providers/Microsoft.Compute/images/$(managedImageName)"
DEST_MANAGED_IMAGE="/subscriptions/$(prodSubscriptionId)/resourceGroups/$(prodResourceGroupName)/providers/Microsoft.Compute/images/$(managedImageName)"
SIG_DEF="/subscriptions/$(prodSubscriptionId)/resourceGroups/$(prodResourceGroupName)/providers/Microsoft.Compute/galleries/$(prodSharedImageGalleryName)/images/$(managedImageName)"
LOCATION=`az sig image-definition show --ids $SIG_DEF --query 'location' -o tsv`
az resource delete --ids $DEST_MANAGED_IMAGE
az resource wait --deleted --ids $DEST_MANAGED_IMAGE
az resource move --destination-group $(prodResourceGroupName) --destination-subscription-id $(prodSubscriptionId) --subscription $(testSubscriptionId) --ids $SOURCE_MANAGED_IMAGE
az sig image-version create -g $(prodResourceGroupName) --gallery-name $(prodSharedImageGalleryName) --gallery-image-definition $(managedImageName) --location $LOCATION --gallery-image-version 0.0.$(Build.BuildId) --managed-image $DEST_MANAGED_IMAGE --storage-account-type standard_zrs