-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.release
66 lines (65 loc) · 2.12 KB
/
Jenkinsfile.release
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
def srvName = 'web-bff'
def gitRepo = 'https://github.com/microservices-kata/petstore-web-bff.git'
def relUser = 'scaleworks'
def relHost = '10.202.129.46'
def registryUrl = '10.202.129.203:5000'
def mvnImage = 'maven:3.5.0-jdk-8-alpine'
def mvnFolder = '/opt/m2'
def relDockerDaemon = "tcp://${relHost}:2376"
def releaseVersion = 'v1.0'
pipeline {
agent any
stages {
stage('代码更新') {
steps {
checkout scm
}
}
stage('构建代码') {
agent {
docker {
reuseNode true
image "${mvnImage}"
args "-v ${mvnFolder}:/root/.m2"
}
}
steps {
sh 'mvn clean package'
}
}
stage('更新契约') {
agent {
docker {
reuseNode true
image "${mvnImage}"
args "-v ${mvnFolder}:/root/.m2"
}
}
steps {
withEnv(["PACT_BROKER_URL=http://${relHost}:2000"]) {
sh "mvn pact:publish"
}
}
}
stage('创建镜像') {
steps {
sh """
mv -f target/*.jar deployment/${srvName}.jar
docker build -t ${registryUrl}/${srvName}:${releaseVersion} -f deployment/Dockerfile.release deployment
docker push ${registryUrl}/${srvName}:${releaseVersion}
docker rmi ${registryUrl}/${srvName}:${releaseVersion}
rm -f deployment/${srvName}.jar
"""
}
}
stage('部署Dev环境') {
steps {
sh """
docker -H ${relDockerDaemon} rm -f ${srvName} | true
docker -H ${relDockerDaemon} run -d --name ${srvName} --net=host ${registryUrl}/${srvName}:${releaseVersion}
docker -H ${relDockerDaemon} image prune --force --all --filter until=`date -d '5 day ago' '+%F'`
"""
}
}
}
}