-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
176 lines (160 loc) · 6.55 KB
/
Jenkinsfile
File metadata and controls
176 lines (160 loc) · 6.55 KB
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
pipeline {
agent any
environment {
DOTNET_CLI_TELEMETRY_OPTOUT = '1'
OUTPUT_DIR = 'output'
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
disableConcurrentBuilds()
timeout(time: 120, unit: 'MINUTES')
}
parameters {
string(name: 'TUTORIAL_URL',
defaultValue: 'https://abp.io/docs/latest/tutorials/book-store?UI=MVC&DB=EF',
description: 'Tutorial URL to validate')
choice(name: 'PERSONA',
choices: ['junior', 'mid', 'senior'],
description: 'Developer persona level')
choice(name: 'ENVIRONMENT',
choices: ['dev', 'staging', 'prod'],
description: 'Target environment')
booleanParam(name: 'KEEP_CONTAINERS',
defaultValue: false,
description: 'Keep Docker containers after run')
}
stages {
stage('Checkout & Setup') {
steps {
checkout scm
sh '''
dotnet --version
dotnet tool install -g Volo.Abp.Studio.Cli
mkdir -p ${OUTPUT_DIR}
'''
}
}
stage('Restore Dependencies') {
steps {
sh 'dotnet restore'
}
}
stage('Build Solution') {
steps {
sh 'dotnet build --configuration Release'
}
}
stage('Run Tests') {
steps {
sh 'dotnet test --configuration Release --no-build --verbosity normal'
}
}
stage('Validate Tutorial') {
environment {
AZURE_OPENAI_API_KEY = credentials('azure-openai-api-key')
AZURE_OPENAI_ENDPOINT = credentials('azure-openai-endpoint')
OPENAI_API_KEY = credentials('openai-api-key')
}
steps {
script {
try {
sh """
dotnet run --project src/Validator.Orchestrator -- run \
--url "${params.TUTORIAL_URL}" \
--persona "${params.PERSONA}" \
--output ./${OUTPUT_DIR} \
${params.KEEP_CONTAINERS ? '--keep-containers' : ''} \
--timeout ${params.ENVIRONMENT == 'prod' ? '120' : '60'}
"""
} catch (Exception e) {
currentBuild.result = 'UNSTABLE'
echo "Validation completed with warnings: ${e.message}"
}
}
}
}
stage('Generate Reports') {
steps {
script {
if (fileExists("${env.OUTPUT_DIR}/summary.json")) {
def summary = readJSON file: "${env.OUTPUT_DIR}/summary.json"
// Generate HTML report
sh """
dotnet run --project src/Validator.Orchestrator -- \
generate-report --input ${env.OUTPUT_DIR}/summary.json \
--output ${env.OUTPUT_DIR}/report.html
"""
// Archive results
archiveArtifacts artifacts: "${env.OUTPUT_DIR}/**/*", fingerprint: true
// Publish HTML report
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: "${env.OUTPUT_DIR}",
reportFiles: 'report.html',
reportName: 'Tutorial Validation Report'
])
// Set build status based on validation result
if (summary.OverallStatus != 'Passed') {
currentBuild.result = 'UNSTABLE'
}
}
}
}
}
stage('Deploy') {
when {
anyOf {
branch 'main'
branch 'develop'
}
}
steps {
script {
if (params.ENVIRONMENT == 'prod' && currentBuild.result == 'SUCCESS') {
// Build and push Docker image
docker.withRegistry("${env.REGISTRY_URL}", "${env.REGISTRY_CREDENTIALS}") {
def customImage = docker.build("tutorial-validator:${env.BUILD_ID}", "-f ./docker/Dockerfile .")
customImage.push()
}
}
}
}
}
}
post {
always {
// Clean up
sh '''
docker-compose -f ./docker/docker-compose.yml down -v --remove-orphans 2>/dev/null || true
docker system prune -f 2>/dev/null || true
'''
// Send notifications
script {
if (currentBuild.result == 'SUCCESS') {
emailext (
subject: "Build Success: ${env.JOB_NAME} - #${env.BUILD_NUMBER}",
body: """
<p>Build successful for ${params.TUTORIAL_URL}</p>
<p>Persona: ${params.PERSONA}</p>
<p>Environment: ${params.ENVIRONMENT}</p>
<p>Build Number: #${env.BUILD_NUMBER}</p>
<p>View results: <a href="${env.BUILD_URL}">${env.JOB_NAME} - #${env.BUILD_NUMBER}</a></p>
""",
to: "${env.NOTIFICATION_EMAIL}"
)
} else {
emailext (
subject: "Build Failed: ${env.JOB_NAME} - #${env.BUILD_NUMBER}",
body: """
<p>Build failed for ${params.TUTORIAL_URL}</p>
<p>Check console output: <a href="${env.BUILD_URL}console">${env.BUILD_URL}console</a></p>
""",
to: "${env.NOTIFICATION_EMAIL}"
)
}
}
}
}
}