forked from sidd-harth/kubernetes-devops-security
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
129 lines (99 loc) · 3.73 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
pipeline {
agent any
tools{
jdk 'jdk11'
maven 'maven'
}
// below code removing old builds
// options {
// buildDiscarder logRotator(artifactDaysToKeepStr: '1', artifactNumToKeepStr: '1', daysToKeepStr: '1', numToKeepStr: '1')
// }
stages {
stage('Build Artifact') {
steps {
// sh "echo passed"
sh "mvn clean package -DskipTests=true"
archiveArtifacts artifacts: 'target/*.jar' //so that they can be downloaded later
sh "echo $GIT_COMMIT --short HEAD"
}
}
stage('Unit test - Junit and Jacoco') {
steps {
sh "mvn test"
}
/* post {
always {
junit 'target/surefire-reports/*.xml'
jacoco (execPattern : 'target/jacoco.exec' )
}
} */
}
/* stage('SonarQube Analysis') {
steps {
// def mvn = tool 'Default Maven';
withSonarQubeEnv('sonarqube') {
sh "mvn clean verify sonar:sonar \
-Dsonar.projectKey=numeric-application \
-Dsonar.projectName='numeric-application' \
-Dsonar.host.url=http://64.2129:9000 "
}
// timeout(time: 2, unit: 'MINUTES') {
script {
waitForQualityGate abortPipeline: true
}
// }
}
} */
/* stage('Vulnerability Scan ') {
//steps {
//sh "mvn dependency-check:check"
//}
}*/
/* post {
always {
dependencyCheckPublisher pattern: 'target/dependency-check-report.xml'
}
}*/
stage('Docker build and push') {
steps {
script{
withDockerRegistry(credentialsId: 'dockerhub') {
sh "printenv"
sh 'docker build -t harshakp06/numeric-app:""$GIT_COMMIT"" .'
sh 'docker push harshakp06/numeric-app:""$GIT_COMMIT""'
}
}
}
}
// git clone https://github.com/harshakp06/argocd-deploy.git
//cd argocd-deploy
// git pull
// sed -i 's#replace#harshakp06/numeric-app:${GIT_COMMIT}#g' argocd/k8s_deployment_service.yaml
/* stage('GIT Push') {
steps {
script{
withCredentials([gitUsernamePassword(credentialsId: 'github', gitToolName: 'Default')]) {
sh '''
pwd
git checkout main
git pull
GIT_COMIT=${GIT_COMMIT}
sed -i 's#harshakp06/numeric-app:.*#harshakp06/numeric-app:${GIT_COMIT}#g' argocd/k8s_deployment_service.yaml
git add argocd/k8s_deployment_service.yaml
git commit -m "changes to image version"
git push -u origin HEAD:main
'''
}
}
}
} */
}
// post {
// always {
// junit 'target/surefire-reports/*.xml'
// jacoco execPattern: 'target/jacoco.exec'
// pitmutation mutationStatsFile: '**/target/pit-reports/**/mutations.xml'
// dependencyCheckPublisher pattern: 'target/dependency-check-report.xml'
//}
//}
}