-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
213 lines (188 loc) · 8.21 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
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
@Library('jenkins-shared-libs@feature/lib_refactor')_
pipeline {
agent { label 'docker'}
environment {
ARTIFACTORY_SERVER_REF = 'artifactory'
artifactVersion = "${new Date().format('yy.MM.dd')}"
pomPath = 'pom.xml'
snapshotRepository = 'libs-snapshot-local'
releaseRepository = 'libs-release-local'
snapshotDependenciesRepository = 'libs-snapshot'
releaseDependeciesRepository = 'libs-release'
}
parameters {
string(name: 'HAS_CHANGES', defaultValue: 'N')
string(name: 'IS_MASTER', defaultValue: 'N')
}
stages {
stage('Pipeline setup') {
parallel {
stage('Triggers setup') {
agent{
docker {
image 'maven:3-alpine'
args '-v $HOME/.m2:/root/.m2 --network user-default'
reuseNode true
label 'docker'
}
}
steps {
script {
triggerStarter ((env.JOB_NAME.tokenize('/'))[0])
/*withCredentials([string(credentialsId: 'github-orwell-cicd-webhook-token', variable: 'githubWebhookGenericToken')]) {
properties([
pipelineTriggers([
[
$class : 'GenericTrigger',
causeString : 'Push made',
token : githubWebhookGenericToken,
genericHeaderVariables : [
[key: 'X-GitHub-Event', regexpFilter: '']
],
genericVariables : [
[key: 'project', value: '$.repository.name'],
[key: 'branch', value: '$.ref']
],
regexpFilterExpression : (env.JOB_NAME.tokenize('/'))[0] + ',push',
regexpFilterText : '$project,$x_github_event',
printContributedVariables: true,
printPostContent : true
]
])
])
}*/
}
}
}
stage('Artifactory setup') {
agent{
docker {
image 'maven:3-alpine'
args '-v $HOME/.m2:/root/.m2 --network user-default'
reuseNode true
label 'docker'
}
}
steps {
script {
def MAVEN_HOME = sh(script: 'echo $MAVEN_HOME', returnStdout: true).trim()
// Obtain an Artifactory server instance, defined in Jenkins --> Manage:
server = Artifactory.server ARTIFACTORY_SERVER_REF
def descriptor = Artifactory.mavenDescriptor()
// def end = '-SNAPSHOT'
descriptor.pomFile = pomPath
def scmVars = checkout scm
if (!( scmVars.GIT_BRANCH == 'master')) {
artifactVersion = artifactVersion + '-SNAPSHOT'
}
if ( scmVars.GIT_BRANCH == 'master') {
env.IS_MASTER='Y'
}
if (scmVars.GIT_COMMIT != scmVars.GIT_PREVIOUS_COMMIT) {
env.HAS_CHANGES='Y'
}
descriptor.version = artifactVersion
descriptor.transform()
rtMaven = Artifactory.newMavenBuild()
env.MAVEN_HOME = MAVEN_HOME
rtMaven.deployer releaseRepo: releaseRepository, snapshotRepo: snapshotRepository, server: server
rtMaven.resolver releaseRepo: releaseDependeciesRepository, snapshotRepo: snapshotDependenciesRepository, server: server
rtMaven.opts = '-DprofileIdEnabled=true'
rtMaven.deployer.deployArtifacts = false // Disable artifacts deployment during Maven run
buildInfo = Artifactory.newBuildInfo()
}
}
}
}
}
stage('Unit test') {
when {
expression { env.HAS_CHANGES == 'Y' }
beforeAgent true
}
agent{
docker {
image 'maven:3-alpine'
args '-v $HOME/.m2:/root/.m2 --network user-default'
reuseNode true
label 'docker'
}
}
steps {
script {
rtMaven.run pom: pomPath, goals: '-U clean test -Pdeploy'
}
}
/*
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
*/
}
stage('Build') {
when {
expression { env.HAS_CHANGES == 'Y' }
beforeAgent true
}
agent{
docker {
image 'maven:3-alpine'
args '-v $HOME/.m2:/root/.m2 --network user-default'
reuseNode true
label 'docker'
}
}
steps {
script {
rtMaven.run pom: pomPath, goals: '-U clean package -DskipTests -Pdeploy', buildInfo: buildInfo
}
}
post {
always {
archiveArtifacts artifacts: '**/target/*.jar'
}
}
}
stage('Publish') {
when {
expression { env.HAS_CHANGES == 'Y' }
beforeAgent true
}
agent{
docker {
image 'maven:3-alpine'
args '-v $HOME/.m2:/root/.m2 --network user-default'
reuseNode true
label 'docker'
}
}
steps {
script {
server.publishBuildInfo buildInfo
rtMaven.deployer.deployArtifacts buildInfo
}
}
}
stage('Deploy') {
when {
expression { env.HAS_CHANGES == 'Y' && env.IS_MASTER == 'N' }
beforeAgent true
}
steps {
script {
pom = readMavenPom file: pomPath
pom = readMavenPom file: pomPath
kUser = 'svc_core'
hostsDeploy = 'sid-hdf-g4-1.node.sid.consul'
nimbusHost = 'sid-hdf-g1-1.node.sid.consul'
zkHost = 'sid-hdf-g1-0.node.sid.consul:2181,sid-hdf-g1-1.node.sid.consul:2181,sid-hdf-g1-2.node.sid.consul:2181'
mainClass = 'com.orwellg.yggdrasil.interpartyrelationship.topology.ReadInterpartyRelationshipTopology'
groupId = 'com.orwellg.yggdrasil'
stormDeploy pom.artifactId , pom.version , groupId, kUser , hostsDeploy , nimbusHost ,zkHost, mainClass
}
}
}
}
}