-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
35 lines (35 loc) · 1.42 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
def srvName = 'order-service'
def gitRepo = 'https://github.com/microservices-kata/petstore-order-service.git'
def devUser = 'scaleworks'
def devHost = '10.202.129.46'
def registryUrl = '10.202.129.203:5000'
def mvnImage = 'maven:3.5.0-jdk-8-alpine'
def mvnFolder = '/opt/m2'
node {
stage('代码更新') {
checkout scm: [$class: 'GitSCM', branches: [[name: '*/master']],
userRemoteConfigs: [[url: gitRepo]]]
}
docker.image("${mvnImage}").inside("-v ${mvnFolder}:/root/.m2") {
stage('构建代码') {
sh 'mvn clean package'
}
// stage('验证契约') {
// sh "export PACT_BROKER_URL=\"http://${devHost}:2000\"; mvn pact:verify"
// }
}
stage('创建镜像') {
sh "mv -f target/*.jar deployment/${srvName}.jar"
sh "docker build -t ${registryUrl}/${srvName}:$BUILD_NUMBER deployment"
sh "docker push ${registryUrl}/${srvName}:$BUILD_NUMBER"
sh "docker rmi ${registryUrl}/${srvName}:$BUILD_NUMBER"
}
stage('部署Dev环境') {
def devDockerDaemon = "tcp://${devHost}:2376"
sh "docker -H ${devDockerDaemon} rm -f ${srvName} | true"
sh "docker -H ${devDockerDaemon} run -d --name ${srvName} --net=host \
${registryUrl}/${srvName}:$BUILD_NUMBER"
sh "docker -H ${devDockerDaemon} image prune --force --all \
--filter until=`date -d '5 day ago' '+%F'`"
}
}