-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile_Sandbox
More file actions
210 lines (201 loc) · 6 KB
/
Jenkinsfile_Sandbox
File metadata and controls
210 lines (201 loc) · 6 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
209
210
def propfile
def FAILED_STAGE
def HOSTS
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
"""
}
}
environment {
javadoc = 'false'
HOSTS_DEPLOY = 'rhscmdev02.sterling.com'
test = 'ls -lrt'
token = credentials('id_rsa_jenkins')
notification = credentials('Sandbox_webhook')
}
stages {
stage('Build & Unit Test') {
steps {
container('gradle') {
script {
withMaven(maven: 'MAVEN-3.6.3') {
FAILED_STAGE=env.STAGE_NAME
echo 'I am executing build and unit test'
echo env.BRANCH_NAME
echo env.GIT_BRANCH
//sh "mvn -Drevision=EJB-${env.GIT_BRANCH}-build-${env.BUILD_NUMBER}-SNAPSHOT -f sample-java-app/pom.xml clean package"
propfile = readProperties(file: './project.properties_PROD')
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 {javadoc == "true" }}
steps {
container('gradle') {
script {
withMaven(maven: 'MAVEN-3.6.3') {
withSonarQubeEnv(installationName: 'Sonarqube') {
FAILED_STAGE=env.STAGE_NAME
echo 'I am executing code quality using sonarqube'
echo ' Update the line below when we switch to actual EJB repo'
// sh './gradle Sonarqube'
}
//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') {
FAILED_STAGE=env.STAGE_NAME
echo 'copying the ear file from the individual target directories and copying it to artifacts directory'
/*
sh "echo propfile['ear_file']"
sh '''
rm -rf $WORKSPACE/artifacts
mkdir -p $WORKSPACE/artifacts
cd $WORKSPACE
cp -r dist/libs/EJBIntegrationEAR.ear artifacts/
cp -r deployment/* artifacts/
tar -czvf artifact.tar.gz $WORKSPACE/artifacts/*
ls -lrt sample-java-app/target/
'''
*/
//sh "mvn clean deploy -Drevision=EJB-${env.GIT_BRANCH}-build-${env.BUILD_NUMBER}-SNAPSHOT -Dmaven.test.skip=true"
}
}
}
}
}
stage("Deploy") {
when { expression {env.GIT_BRANCH == 'dev' || propfile['publish_pkg'] == "true" }}
steps {
container('gradle') {
script {
withMaven(maven: 'MAVEN-3.6.3') {
FAILED_STAGE=env.STAGE_NAME
USERNAME=propfile['USERNAME_DEPLOY']
HOSTS=propfile['HOSTS_DEPLOY']
echo HOSTS
/*
mkdir -p $WORKSPACE/artifacts
echo "Pulling artifact from the repository to deploy"
sh "mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get \
-DrepoUrl=https://archiva.sgnt.devops.accentureanalytics.com/repository/snapshots \
-Dartifact=io.buildpacks.example:sample:${propfile['artifact_name']}:jar -Ddest=$WORKSPACE/artifacts/myfile.jar"
sh "ls -la $WORKSPACE/artifacts"
HOSTS.tokenize(',').each { HOSTNAME ->
echo "${HOSTNAME}"
cp -r /c/Windows/System32/config/systemprofile/AppData/Local/Jenkins/.jenkins/workspace/DevOps_EJB_Build/artifacts/* $WORKSPACE/artifacts/
scp -rp $WORKSPACE/artifacts/propfile['ear_file'] ${USERNAME}@${HOSTNAME}:propfile['deploy_dir']/
scp -rp $WORKSPACE/artifacts/propfile['target_env']/propfile['migration_file'] ${USERNAME}@${HOSTNAME}:propfile['deploy_dir']/
scp -rp $WORKSPACE/artifacts/propfile['target_env']/propfile['properties_file'] ${USERNAME}@${HOSTNAME}:propfile['deploy_dir']/
scp -rp $WORKSPACE/artifacts/propfile['target_env']/propfile['log4j_file'] ${USERNAME}@${HOSTNAME}:propfile['deploy_dir']/
ssh /bin/chmod 666 propfile['deploy_dir']/propfile['ear_file']
ssh /bin/chmod 666 propfile['deploy_dir']/propfile['migration_file']
ssh /bin/chmod 666 propfile['deploy_dir']/propfile['properties_file']
ssh /bin/chmod 666 propfile['deploy_dir']/propfile['log4j_file']
ssh cd propfile['deploy_dir'];/usr/local/was/bin/wasMigrate.s -m EcomEjbProxy.mig -r `date "+%Y%m%d%H%M"`
}
*/
}
}
}
}
}
stage('Post Deploy Tests') {
parallel {
stage('Functional Test') {
steps {
//withCredentials([sshUserPrivateKey(credentialsId: "id_rsa_jenkins", keyFileVariable: 'keyfile')]) {
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 {
switch(HOSTS) {
case "10.6.74.242":
TARGETENV="dev1"
break
default:
TARGETENV="DEFAULT"
break
}
echo "$TARGETENV"
}
}
}
}