-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
60 lines (60 loc) · 2.08 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
pipeline {
agent any
tools {
maven 'maven-3.8.6'
}
environment {
DATE = new Date().format('yy.M')
TAG = "${DATE}.${BUILD_NUMBER}"
rancherCredential = 'Rancher'
aliyuncsCredential = 'Aliyuncs'
dockerRegistry = 'https://registry.cn-hangzhou.aliyuncs.com'
projectDir = "${WORKSPACE}"
dockerImage = 'registry.cn-hangzhou.aliyuncs.com/rlm/mygraph'
workloadUrl = "/project/${params.ProjectId}/workloads/deployment:renlm:${params.AppName}"
}
stages {
stage ('Maven Build') {
steps {
echo "Maven构建..."
dir("${projectDir}") {
script {
def profile = params.Profile == null ? 'prod' : params.Profile
sh "mvn clean package -P ${profile} -T 1C -Dmaven.test.skip=true -Dmaven.compile.fork=true"
}
}
}
}
stage('Docker Build') {
steps {
script {
echo "构建镜像..."
dir("${projectDir}") {
docker.withRegistry("${dockerRegistry}", "${aliyuncsCredential}") {
docker.build("${dockerImage}:${TAG}", "-f ${projectDir}/Dockerfile .")
}
}
}
}
}
stage('Publish Image') {
steps {
script {
echo "推送镜像..."
docker.withRegistry("${dockerRegistry}", "${aliyuncsCredential}") {
docker.image("${dockerImage}:${TAG}").push()
docker.image("${dockerImage}:${TAG}").push("latest")
sh "docker rmi ${dockerImage}:latest"
sh "docker rmi ${dockerImage}:${TAG}"
}
}
}
}
stage('Deploy') {
steps {
echo "部署应用..."
rancherRedeploy alwaysPull: true, credential: "${rancherCredential}", images: "${dockerImage}", workload: "${workloadUrl}"
}
}
}
}