-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
138 lines (131 loc) · 6.42 KB
/
Jenkinsfile
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
library '[email protected]'
def isDependabot(branchName) { return branchName.toString().startsWith("dependabot/nuget") }
def isMaster(branchName) { return branchName == "master" }
def isTest(branchName) { return branchName == "test" || branchName == "feature/bicep" }
podTemplate(label: pod.label,
containers: pod.templates + [
containerTemplate(name: 'dotnet', image: 'mcr.microsoft.com/dotnet/sdk:6.0-alpine', ttyEnabled: true, command: '/bin/sh -c', args: 'cat'),
containerTemplate(name: 'powershell', image: 'mcr.microsoft.com/azure-powershell:7.2.0-alpine-3.14', ttyEnabled: true, command: '/bin/sh -c', args: 'cat')
]
) {
def branch = (env.BRANCH_NAME)
def resourceGroup = 'repository-validator-prod'
def appName = 'ptcs-github-validator'
def gitHubOrganization = 'by-pinja'
def functionsProject = 'ValidationLibrary.AzureFunctions'
def zipName = 'publish.zip'
def publishFolder = 'publish'
def environment = isMaster(branch) ? 'Production' : 'Development'
node(pod.label) {
stage('Checkout') {
checkout scm
}
container('dotnet') {
stage('Build') {
sh """
# Build the whole system, but only publish Azure Functions project
dotnet build
cd $functionsProject
dotnet publish -c Release -o $publishFolder --version-suffix ${env.BUILD_NUMBER}
cd ..
"""
}
stage('Test') {
sh """
dotnet test
dotnet run --project Runner -- generate-document
"""
}
}
if (isTest(branch) || isMaster(branch) || isDependabot(branch)){
container('powershell') {
stage('Package') {
sh """
pwsh -command "Compress-Archive -DestinationPath $zipName -Path $functionsProject/$publishFolder/*"
"""
}
if (isTest(branch) || isDependabot(branch)){
toAzureTestEnv {
def now = new Date().getTime()
def ciRg = 'repo-ci-' + now
def ciAppName = 'repo-ci-' + now
stage('Create temporary Resource Group'){
sh """
pwsh -command "New-AzResourceGroup -Name '$ciRg' -Location 'North Europe' -Tag @{subproject='2026956'; Description='Continuous Integration'}"
"""
}
withCredentials([
string(credentialsId: 'hjni_github_token', variable: 'GH_TOKEN')
]) {
stage('Create test environment'){
sh """
pwsh -command "&./Deployment/Create-Environment.ps1 -ResourceGroup $ciRg -AppName $ciAppName -GitHubToken $GH_TOKEN -GitHubOrganization $gitHubOrganization -Environment $environment"
"""
}
}
try {
stage('Publish to test environment') {
sh """
pwsh -command "Publish-AzWebApp -ResourceGroupName $ciRg -Name $ciAppName -ArchivePath $zipName -Force"
"""
}
stage('Add availability test') {
sh """
pwsh -command "&./Deployment/Add-AvailabilityTest.ps1 -ResourceGroupName $ciRg"
"""
}
stage('Create .runsettings-file acceptance tests') {
sh """
pwsh -command "&./Deployment/Create-RunSettingsFile.ps1 -ResourceGroup $ciRg -WebAppName $ciAppName"
"""
}
container('dotnet') {
stage('Acceptance tests') {
sh """
cd AcceptanceTests
dotnet test --settings '.runsettings'
"""
}
}
}
finally {
stage('Delete test environment'){
sh """
pwsh -command "Remove-AzResourceGroup -Name '$ciRg' -Force"
"""
}
}
}
}
if (isMaster(branch)){
toAzureEnv("PTCG_Azure_SP") {
withCredentials([
string(credentialsId: 'hjni_github_token', variable: 'GH_TOKEN')
]){
stage('Create production environment') {
sh """
pwsh -command "&./Deployment/Create-Environment.ps1 -ResourceGroup $resourceGroup -AppName $appName -GitHubToken $GH_TOKEN -GitHubOrganization $gitHubOrganization -Environment Production"
"""
}
}
stage('Publish to production environment') {
sh """
pwsh -command "Publish-AzWebApp -ResourceGroupName $resourceGroup -Name $appName -ArchivePath $zipName -Force"
"""
}
stage('Add availability test') {
sh """
pwsh -command "&./Deployment/Add-AvailabilityTest.ps1 -ResourceGroupName $resourceGroup -WebAppName $appName"
"""
}
stage('Warmup and validate'){
sh """
pwsh -command "&./Testing/Test-Validation.ps1 -ResourceGroup $resourceGroup -WebAppName $appName"
"""
}
}
}
}
}
}
}