-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdocker-framework-pipeline.groovy
201 lines (179 loc) · 7.36 KB
/
docker-framework-pipeline.groovy
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
node {
// -------------------------------------------------------------------------------------------------------
// Parameters
// docker
def DOCKER_URL = 'jfrogchina.local:8081'
// sonarqube
def SONAR_HOST_URL = 'http://jfrogchina.local:9000'
def SONAR_SERVER = 'sonar'
def SONAR_SCANNER_TOOL = 'sonarscanner'
def SONAR_PROJECT_KEY = "${JOB_NAME}"
def SONAR_SOURCES = 'maven-example/multi3/src'
// artifactory
def ART_URL = 'http://jfrogchina.local:8081/artifactory/'
def CREDENTIALSID = 'arti'
def PASSWORDVARIABLE = 'PASSWORD'
def USERNAMEVARIABLE = 'USERNAME'
def SOURCEREPO = 'docker-dev-local'
def TARGETREPO = 'docker-release-local'
def RESOLVE_SNAPSHOT_REPO = 'maven-snapshots-virtual'
def RESOLVE_RELEASE_REPO = 'maven-releases-virtual'
def DEPLOY_SNAPSHOT_REPO = 'maven-snapshots-local'
def DEPLOY_RELEASE_REPO = 'maven-releases-local'
def artServer = Artifactory.server('arti-demo')
def rtMaven = Artifactory.newMavenBuild()
def buildInfo = Artifactory.newBuildInfo()
// git
def GIT_URL = 'https://github.com/gyzong1/JfrogChina.git'
// maven
def MAVEN_TOOL = 'maven'
def MAVEN_GOALS = 'clean install'
def POM_PATH = 'maven-example/pom.xml'
// -------------------------------------------------------------------------------------------------------
stage ('Checkout Code') {
git GIT_URL
}
dir('project-examples') {
stage ('Build Maven') {
rtMaven.resolver server: artServer, releaseRepo: RESOLVE_RELEASE_REPO, snapshotRepo: RESOLVE_SNAPSHOT_REPO
rtMaven.deployer server: artServer, releaseRepo: DEPLOY_RELEASE_REPO, snapshotRepo: DEPLOY_SNAPSHOT_REPO
rtMaven.tool = MAVEN_TOOL
rtMaven.run pom: POM_PATH, goals: MAVEN_GOALS, buildInfo: buildInfo
}
}
dir('docker-lifecycle-scripts') {
stage('Resolve') {
dir('docker-framework') {
withCredentials([usernamePassword(credentialsId: CREDENTIALSID, passwordVariable: PASSWORDVARIABLE, usernameVariable: USERNAMEVARIABLE)]) {
def uname=env.USERNAME
def pw=env.PASSWORD
artServer.username=uname
artServer.password=pw
def curlstr="curl -u"+uname+':'+pw+" "+"\'"+ART_URL
def artDocker= Artifactory.docker server: artServer
def tomcatverstr=curlstr+ "api/search/latestVersion?g=org.apache&a=apache-tomcat&repos=tomcat-local'"
println(tomcatverstr)
sh tomcatverstr+' > tomcat/version.txt'
env.TOMCAT_VERSION=readFile('tomcat/version.txt')
sh 'echo $TOMCAT_VERSION'
def downloadSpec = """{
"files": [
{
"pattern": "tomcat-local/java/jdk-8u201-linux-x64.tar.gz",
"target": "jdk/jdk-8-linux-x64.tar.gz",
"flat":"true"
},
{
"pattern": "tomcat-local/org/apache/apache-tomcat/apache-tomcat-"""+env.TOMCAT_VERSION+""".tar.gz",
"target": "tomcat/apache-tomcat-8.tar.gz",
"flat":"true"
}
]
}"""
artServer.download(downloadSpec, buildInfo)
sh 'pwd'
sh 'ls -al jdk'
sh 'ls -al tomcat'
sh 'echo download complete'
}
}
}
stage('docker build') {
dir('docker-framework') {
withCredentials([usernamePassword(credentialsId: CREDENTIALSID, passwordVariable: PASSWORDVARIABLE, usernameVariable: USERNAMEVARIABLE)]) {
def uname=env.USERNAME
def pw=env.PASSWORD
artServer.username=uname
artServer.password=pw
def curlstr="curl -u"+uname+':'+pw+" "+"\'"+ART_URL
def artDocker= Artifactory.docker server: artServer
buildInfo.env.collect()
println('starting build '+env.BUILD_NUMBER)
def tagName=DOCKER_URL+'/docker-virtual/docker-framework:'+env.BUILD_NUMBER
sh 'pwd'
sh 'ls -al'
sh 'cat Dockerfile'
buildInfo.env.capture = true
docker.build(tagName)
buildInfo.env.vars['status2'] = 'pre-test'
artDocker.push(tagName, 'docker-virtual', buildInfo)
//artDocker.deployer.addProperty("status", "in-qa").addProperty("compatibility", "1", "2", "3")
artServer.publishBuildInfo(buildInfo)
println('Retagging Image')
sh 'sed -E "s/@/$BUILD_NUMBER/" retag-dev > retag_out_dev.json'
sh 'cat retag_out_dev.json'
def retagstr=curlstr+"api/docker/docker-dev-local/v2/promote' -X POST -H 'Content-Type: application/json' -T retag_out_dev.json"
sh retagstr
}
}
}
stage('testing') {
dir('docker-framework/framework-test') {
withCredentials([usernamePassword(credentialsId: CREDENTIALSID, passwordVariable: PASSWORDVARIABLE, usernameVariable: USERNAMEVARIABLE)]) {
def uname=env.USERNAME
def pw=env.PASSWORD
artServer.username=uname
artServer.password=pw
def curlstr="curl -u"+uname+':'+pw+" "+"\'"+ART_URL
def artDocker= Artifactory.docker server: artServer
println('Get the latest version of the tomcat war from maven-snapshots-local repo. We only want war files that have been released')
def warverstr=curlstr+ "api/search/latestVersion?g=org.jfrog.test&a=multi3&repos=maven-snapshots-local&v=3.7-SNAPSHOT'"
sh warverstr +' > war/version.txt'
env.WARVER=readFile('war/version.txt')
def downloadSpecWar = """{
"files": [
{
"pattern": "maven-snapshots-local/org/jfrog/test/multi3/3.7-SNAPSHOT/multi3-"""+env.WARVER+""".war",
"target": "war/webservice.war",
"flat": "true"
}
]
}""" //"//DownloadSpec
println(downloadSpecWar)
artServer.download(downloadSpecWar)
sh "sed -i 's#docker_ip#${DOCKER_URL}/docker-virtual#' Dockerfile"
echo "===================================="
sh "cat Dockerfile"
def tagNameTest=DOCKER_URL+'/docker-virtual/docker-framework-test:'+env.BUILD_NUMBER
docker.build(tagNameTest)
docker.image(tagNameTest).withRun('-p 8181:8181') {c ->
sleep 5
sh 'curl "http://localhost:8181/swampup/"'
}
}
}
}
stage('promote') {
dir('docker-framework/framework-test') {
withCredentials([usernamePassword(credentialsId: CREDENTIALSID, passwordVariable: PASSWORDVARIABLE, usernameVariable: USERNAMEVARIABLE)]) {
def uname=env.USERNAME
def pw=env.PASSWORD
artServer.username=uname
artServer.password=pw
def curlstr="curl -u"+uname+':'+pw+" "+"\'"+ART_URL
def artDocker= Artifactory.docker server: artServer
def promotionConfig = [
'buildName' : env.JOB_NAME,
'buildNumber' : env.BUILD_NUMBER,
'targetRepo' : TARGETREPO,
'comment' : 'Framework works with latest version of application to pass test',
'sourceRepo' : SOURCEREPO,
'status' : 'Released',
'includeDependencies': false,
'failFast' : false,
'copy' : true
]
// Promote build
artServer.promote promotionConfig
dir('..') {
sh 'ls -l'
sh 'sed -E "s/@/$BUILD_NUMBER/" retag-release.json > retag_out_release.json'
sh 'cat retag_out_release.json'
def retagstr=curlstr+"api/docker/docker-release-local/v2/promote' -X POST -H 'Content-Type: application/json' -T retag_out_release.json"
sh retagstr
}
}
}
}
}
}