-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile_AIP
More file actions
208 lines (208 loc) · 7.32 KB
/
Jenkinsfile_AIP
File metadata and controls
208 lines (208 loc) · 7.32 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
def propfile
def allJob = env.JOB_NAME.tokenize('/') as String[];
def projectName = allJob[2];
pipeline {
agent {
kubernetes {
label 'SpringBootRestApp'
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
component: ci
spec:
containers:
- name: gradle
image: gradle:3.5-jdk8-alpine
command:
- cat
tty: true
"""
}
}
stages {
stage('Build & Unit Test') {
steps {
container('gradle') {
script {
withMaven(maven: 'MAVEN-3.6.3') {
echo 'I am executing build and unit test'
echo 'use the command below when we switch to EJB source'
//sh 'gradle --no-daemon clean build'
echo 'Add gradle clean and build for EJB and comment this step'
sh "mvn -Drevision=${projectName}-${env.GIT_BRANCH}-build-${env.BUILD_NUMBER}-SNAPSHOT -f sample-java-app/pom.xml clean package"
propfile = readProperties(file: './project.properties')
if (propfile['javadoc'] == "true") {
sh 'mvn javadoc:aggregate'
}
if (propfile['jacoco'] == "true") {
jacoco(
execPattern: '**/*.exec',
classPattern: '**/*.class',
sourcePattern: '**/*.java',
exclusionPattern: '**/test*'
)
}
}
}
}
}
}
stage('Code Quality') {
when { expression {propfile['code_quality'] == "true" }}
steps {
container('gradle') {
withMaven(maven: 'MAVEN-3.6.3') {
withSonarQubeEnv(installationName: 'Sonarqube') {
echo 'I am executing code quality using sonarqube'
echo "Change the line below when we switch to the actual EJB repo"
// sh 'gradle SonarQube'
echo 'Remove the line below when we switch to the actual EJB repo'
sh "mvn -Drevision=${projectName}-${env.GIT_BRANCH}-build-${env.BUILD_NUMBER}-SNAPSHOT -f sample-java-app/pom.xml -Dsonar.projectName=EJB_${env.GIT_BRANCH} -Dsonar.projectKey=EJB_sample sonar:sonar"
}
sleep(60)
timeout(time: 1, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
}
}
stage("Publish Package") {
when { expression {env.GIT_BRANCH == 'dev' || propfile['publish_pkg'] == "true" }}
steps {
container('gradle') {
script {
withMaven(maven: 'MAVEN-3.6.3') {
echo 'I am pushing the artifact with unique name showing the branch from which it is generated, to Archiva'
echo 'Replace the next 4 lines to reflect the EJB artifact and push it to archiva'
echo 'Use the 5 lines below when we switch to the actual EJB repo'
/* echo 'copying the jar and war files from the individual target directories and copying it to artifacts directory '
sh "mkdir -p $WORKSPACE/artifacts"
sh "cp /dist/libs/* $WORKSPACE/artifacts/"
echo 'create a tar file on the Jenkins server'
sh "cd $WORKSPACE/artifacts/ && tar -cvzf artifact.tar * && md5sum artifact.tar archiveArtifacts artifacts: 'artifacts/*.tar', fingerprint: true
*/
echo 'Remove the 3 lines below when we switch to the actual EJB repo'
// sh "mv sample-java-app/target/sample-0.0.1-SNAPSHOT.jar sample-java-app/target/EJB_build-${BUILD_NUMBER}_branch-${env.GIT_BRANCH}.jar"
sh 'ls -lrt sample-java-app/target/'
sh "mvn clean deploy -Drevision=${projectName}-${env.GIT_BRANCH}-build-${env.BUILD_NUMBER}-SNAPSHOT -Dmaven.test.skip=true"
}
}
}
}
}
stage("Deploy") {
when { expression {env.GIT_BRANCH == 'dev' || env.GIT_BRANCH == 'release'|| propfile['feature_deploy'] == "true" }}
steps {
container('gradle') {
script {
withMaven(maven: 'MAVEN-3.6.3') {
if (propfile['feature_deploy'] == "true" ) {
USERNAME=propfile['USERNAME_FEATURE_DEPLOY']
HOSTS=propfile['HOSTS_FEATURE_DEPLOY']
}
if (env.GIT_BRANCH == 'dev' ) {
USERNAME=propfile['USERNAME_DEV_DEPLOY']
HOSTS=propfile['HOSTS_DEV_DEPLOY']
}
if (env.GIT_BRANCH == 'release') {
USERNAME=propfile['USERNAME_RELEASE_DEPLOY']
HOSTS=propfile['HOSTS_RELEASE_DEPLOY']
}
HOSTS.tokenize(',').each { HOSTNAME ->
echo 'I am deploying the artifact into the target environment ${HOSTNAME} as user ${USERNAME}'
echo 'Replace all the lines below for EJB and add the parameters to propfile and make refrences below'
echo 'Accom logic for multiple env and mult servers in each env based on the branch name'
echo 'shutting down the tomcat ESB server'
/* sh 'ssh ${USERNAME}@${HOSTNAME} "$ESB_BIN_PATH stop || sleep 20"'
echo 'force stop any remaining mule process'
sh 'ssh ${USERNAME}@${HOSTNAME} "if [[ $(ps aux | grep /opt/mule/latest/ | grep -vc grep) > 0 ]]; then "kill -9 $(ps -ef|pgrep -f "/opt/mule/latest/bin")"; else echo "do nothing"; fi"'
*/
echo 'tomcat server stopped'
echo 'copying the tar file from jenkins to deployment directory on app and remove the old folders and untarring the new jar and war files'
/* sh 'scp -rp $WORKSPACE/artifacts/artifact.tar $DEPLOYMENT_USER@$DEPOYMENT_SERVER:$DEPLOYMENT_STAGE_DIR/'
sh 'ssh ${USERNAME}@${HOSTNAME} "cd $DEPLOYMENT_STAGE_DIR && rm -rf *.war *.jar"'
sh 'ssh ${USERNAME}@${HOSTNAME} "cd $DEPLOYMENT_STAGE_DIR && tar -xvzf artifact.tar && rm -rf *.jar"'
sh 'ssh ${USERNAME}@${HOSTNAME} "cd $}DEPLOYMENT_DIR} && rm -rf ${ESB_WAR_FOLDERS} && cp -rp ${DEPLOYMENT_STAGE_DIR}/*.war $DEPLOYMENT_DIR"'
*/
echo 'Deployment has been completed'
echo 'starting the tomcat ESB server'
/* sh 'ssh ${USERNAME}@${HOSTNAME} "${ESB_BIN_PATH start}"'
sh 'ssh ${USERNAME}@${HOSTNAME} "sleep 20"'
*/
echo 'tomcat server started'
}
}
}
}
}
}
stage('Post Deploy Tests') {
when { expression {env.GIT_BRANCH == 'dev'}}
parallel {
stage('Functional Test') {
when {expression {propfile['ondemand_functionaltest'] == "true" }}
steps {
script {
FAILED_STAGE=env.STAGE_NAME
echo "I am running Functional Test here"
}
}
}
stage('Security Test') {
when {expression {propfile['ondemand_securitytest'] == "true" }}
steps {
container('gradle') {
script {
withMaven(maven: 'MAVEN-3.6.3') {
FAILED_STAGE=env.STAGE_NAME
echo 'I am running Security Test here'
}
}
}
}
}
stage('Performance Test') {
when {expression {propfile['ondemand_perfomancetest'] == "true" }}
steps {
container('gradle') {
script {
withMaven(maven: 'MAVEN-3.6.3') {
FAILED_STAGE=env.STAGE_NAME
echo 'I am running Performance Test here'
}
}
}
}
}
}
}
}
post {
always {
script {
if (propfile['javadoc'] == "true") {
javadoc(javadocDir: "/$WORKSPACE/target/site/apidocs", keepAll: true)
}
}
}
failure {
/*mail bcc: '',
body: "<b>Example</b><br>\n<br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}",
cc: '',
charset: 'UTF-8',
from: '',
mimeType: 'text/html',
replyTo: '',
subject: "ERROR CI: Project name -> ${env.JOB_NAME}",
to: "foo@foomail.com";*/
echo 'I am sending a notification with failure'
}
success {
echo 'I am sending a notification with success'
}
}
}