forked from shunyeka/JenkinsConfigurationUsingApi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
java_config.xml
217 lines (217 loc) · 9.17 KB
/
java_config.xml
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
209
210
211
212
213
214
215
216
217
<?xml version='1.1' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@2.35">
<actions>
<org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction plugin="pipeline-model-definition@1.3.9"/>
<org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction plugin="pipeline-model-definition@1.3.9">
<jobProperties/>
<triggers/>
<parameters/>
<options/>
</org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction>
</actions>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.plugins.jira.JiraProjectProperty plugin="jira@3.0.8">
<siteName>https://shibani.atlassian.net/</siteName>
</hudson.plugins.jira.JiraProjectProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@2.74">
<script>pipeline {
agent any
environment {
SELENIUM_CHROME_DRIVER_PATH = '/usr/bin/chromedriver'
DEMO_APP_URL = 'http://localhost:8082/Login.jsp'
}
tools {
maven 'maven3.6'
}
stages {
// stage('Start SonarQube Server') {
// steps {
// script {
// sh '''
// docker pull library/sonarqube:latest
// docker run -d -p 9000:9000 sonarqube '''
// sleep 100
// }
// }
// }
stage('Source Code Checkkout'){
steps {
script {
timestamps {
logstash {
checkout([$class: 'GitSCM', branches: [[name: '*/with-snar-config']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'shunyeka-github', url: 'https://github.com/shunyeka/demo-auto-testing.git']]])
echo "successfully checkout completed"
}
}
}
}
}
stage('Static Code Analysis') {
parallel {
stage('Snyk Test') {
steps {
script {
timestamps {
logstash {
sh 'mvn -Dmaven.test.failure.ignore=true snyk:test'
//sh 'mvn -Dmaven.test.failure.ignore=true snyk:monitor'
}
}
}
}
}
stage('SonarQube Test') {
steps {
script {
timestamps {
logstash {
sh 'mvn -Dmaven.test.failure.ignore=true -Dmaven.test.skip=true clean package org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar'
}
}
}
}
}
}
}
stage('Build') {
steps {
script {
timestamps {
logstash {
sh 'mvn -Dmaven.test.failure.ignore=true -Dmaven.test.skip=true clean package'
sh 'mv -f target/*.war target/${JOB_NAME}-${BUILD_NUMBER}.war'
}
}
}
}
}
stage('Create Test Environment') {
steps {
script {
timestamps {
logstash {
sh 'mvn jetty:run-war -Djetty.port=8082 -Dmaven.test.failure.ignore=true -Dmaven.test.skip=true &'
sleep 40
}
}
}
}
}
stage('Automated Testing') {
parallel {
stage('JUnit Test') {
steps {
script {
timestamps {
logstash {
sh 'mvn -Dmaven.test.failure.ignore=true -Dtest=TestWelcome#testUserValidateJunit test'
}
}
}
}
}
stage('Seleniun Test') {
steps {
script {
timestamps {
logstash {
sh 'mvn -Dmaven.test.failure.ignore=true -Dtest=TestWelcome#testUserValidateSelenium -Dselenium.browser=chrome -Dwebdriver.chrome.driver=/usr/bin/chromedriver test'
}
}
}
}
}
}
}
stage('Manual Test') {
steps {
script {
timestamps {
logstash {
user_input=input message: 'Manual Test Passed?', submitterParameter: 'user_input'
sh 'pkill -f jetty'
// sh 'docker kill $(docker ps -q --filter publish=9000)'
}
}
}
}
}
stage('Storing Artifact') {
parallel {
stage('Publish to s3') {
steps {
script {
timestamps {
logstash {
user_input=input message: 'Do you want to publish the Artifact to s3 ?', submitterParameter: 'user_input'
s3Upload consoleLogLevel: 'INFO', dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 's3-artifact-s', excludedFile: '', flatten: false, gzipFiles: true, keepForever: false, managedArtifacts: false, noUploadOnFailure: true, selectedRegion: 'us-east-2', showDirectlyInBrowser: false, sourceFile: 'target/${JOB_NAME}-${BUILD_NUMBER}.war', storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 's3-artifact-s', userMetadata: []
}
}
}
}
}
stage('DockerHub') {
steps {
timestamps {
logstash {
echo 'stored successfully.'
}
}
}
}
stage('AWS ECR') {
steps {
timestamps {
logstash {
echo 'storing successfully.'
}
}
}
}
}
}
stage('JIRA Create Issue') {
steps {
timestamps {
logstash {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'jira-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
sh label: '', script: '''
jira_credential="${USERNAME}:${PASSWORD}"
jira_curl_body="{\\"update\\": {},\\"fields\\": {\\"summary\\": \\"${JOB_NAME}-${BUILD_NUMBER}\\",\\"project\\": {\\"key\\": \\"FP\\" },\\"issuetype\\": {\\"id\\": \\"10005\\"}, \\"description\\": { \\"type\\": \\"doc\\", \\"version\\": 1, \\"content\\": [ { \\"type\\": \\"paragraph\\", \\"content\\": [ { \\"text\\": \\"Issue created by jenkins.\\", \\"type\\": \\"text\\" } ] } ] } } }"
curl --request POST \\
--url \'https://shibani.atlassian.net/rest/api/3/issue\' \\
--user "${jira_credential}" \\
--header \'Accept: application/json\' \\
--header \'Content-Type: application/json\' \\
-d "${jira_curl_body}" -o 'jira-issue.json'
JIRA_KEY=$(jq -r '.id' jira-issue.json)
JIRA_URL="https://shibani.atlassian.net/rest/api/3/issue/${JIRA_KEY}/attachments"
curl -D- -u "${jira_credential}" -X POST -H "X-Atlassian-Token: no-check" -F "file=@jira-issue.json" $JIRA_URL
'''
}
}
}
}
}
}
post {
always {
echo "This is always executed"
}
failure {
timestamps {
logstash {
echo "BuildFailed"
}
}
}
}
}</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
<disabled>false</disabled>
</flow-definition>