-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
118 lines (107 loc) · 3.67 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
trigger:
branches:
include:
- '*'
paths:
include:
- '*'
variables:
MAJOR_VERSION: 0
MINOR_VERSION: 0
PATCH_VERSION: 1
name: $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION).$(Rev:r)
stages:
- stage: ContinuousIntegration
displayName: 'Continous Integration'
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: SetBuildNumber
displayName: 'Set build number'
steps:
- checkout: none
- task: PowerShell@2
displayName: Set build number
inputs:
targetType: 'inline'
script: |
$branchName = "$(Build.SourceBranchName)";
$buildTrigger = "$(Build.Reason)";
$buildVersion = "$(Build.BuildNumber)";
Write-Host "Branch name: $branchName";
Write-Host "Build trigger: $buildTrigger";
Write-Host "Build version: $buildVersion";
if (-not($buildVersion.Contains($branchName) -or $buildVersion.Contains($buildTrigger))) {
$nugetPkgVersion = $buildVersion;
if (-not([string]::IsNullOrWhiteSpace($branchName)) -and ($branchName -ne "main")) {
$nugetPkgVersion = "$nugetPkgVersion-$branchName";
}
Write-Host "Package version: $nugetPkgVersion";
Write-Host "##vso[build.updateBuildNumber]$nugetPkgVersion";
}
else {
Write-Host "Package version: $buildVersion";
}
- job: ValidateTerraform
displayName: 'Validate Terraform'
dependsOn: SetBuildNumber
steps:
- task: TerraformInstaller@1
displayName: 'Install Terraform'
inputs:
terraformVersion: 'latest'
- task: TerraformTaskV4@4
displayName: 'Terraform init'
inputs:
provider: 'azurerm'
command: 'init'
workingDirectory: '$(Build.SourcesDirectory)/src'
backendServiceArm: 'Free Trial(85e5b8d9-d15f-4db3-bfaf-c97182b7cc0b)'
backendAzureRmResourceGroupName: 'terraform-rg'
backendAzureRmStorageAccountName: 'tfstorageaccount12345'
backendAzureRmContainerName: 'tfstate'
backendAzureRmKey: 'container_apps_env.tfstate'
- task: TerraformTaskV4@4
displayName: 'Terraform validate'
inputs:
provider: 'azurerm'
command: 'validate'
- task: TerraformTaskV4@4
displayName: 'Terraform plan'
inputs:
provider: 'azurerm'
command: 'plan'
workingDirectory: '$(Build.SourcesDirectory)/src'
environmentServiceNameAzureRM: 'Free Trial(85e5b8d9-d15f-4db3-bfaf-c97182b7cc0b)'
- stage: ContinuousDelivery
displayName: 'Continuous Delivery'
dependsOn: ContinuousIntegration
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'main'))
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: ApplyTerraform
displayName: 'Apply Terraform'
steps:
- task: TerraformInstaller@1
displayName: 'Install Terraform'
inputs:
terraformVersion: 'latest'
- task: TerraformTaskV4@4
displayName: 'Terraform init'
inputs:
provider: 'azurerm'
command: 'init'
workingDirectory: '$(Build.SourcesDirectory)/src'
backendServiceArm: 'Free Trial(85e5b8d9-d15f-4db3-bfaf-c97182b7cc0b)'
backendAzureRmResourceGroupName: 'terraform-rg'
backendAzureRmStorageAccountName: 'tfstorageaccount12345'
backendAzureRmContainerName: 'tfstate'
backendAzureRmKey: 'container_apps_env.tfstate'
- task: TerraformTaskV4@4
displayName: 'Terraform apply'
inputs:
provider: 'azurerm'
command: 'apply'
workingDirectory: '$(Build.SourcesDirectory)/src'
environmentServiceNameAzureRM: 'Free Trial(85e5b8d9-d15f-4db3-bfaf-c97182b7cc0b)'