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
pipeline {
agent any
environment {
APP_VERSION = '1.0.0'
DEPLOY_ENV = 'staging'
}
stages {
stage('Checkout') {
steps {
checkout scm
echo 'Repository cloned successfully'
}
}
stage('Build') {
steps {
sh 'mvn clean compile'
sh 'mvn package -DskipTests'
echo 'Build completed'
}
}
stage('Test') {
steps {
sh 'mvn test'
dir('reports') {
sh 'ls -la'
}
}
}
stage('Deploy to Staging') {
when {
branch 'main'
}
steps {
sh 'kubectl apply -f deployment-staging.yaml'
echo 'Deployed to staging'
}
}
stage('Deploy to Production') {
when {
branch 'main'
}
steps {
withCredentials([string(credentialsId: 'prod-token', variable: 'TOKEN')]) {
sh 'deploy-prod.sh'
}
echo 'Deployed to production'
}
}
}
}