forked from openeuler-mirror/euler-copilot-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
41 lines (35 loc) · 1.52 KB
/
Jenkinsfile
File metadata and controls
41 lines (35 loc) · 1.52 KB
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
node {
properties([
parameters([
string(name: "REPO", defaultValue: "framework-dev", description: "当前项目名")
])
])
echo "拉取代码仓库"
checkout scm
def BUILD = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
def reg = ""
withCredentials([string(credentialsId: "reg_host", variable: "REG_HOST")]) {
reg = "${REG_HOST}"
}
echo "构建当前分支Docker Image镜像"
docker.withRegistry("https://${reg}", "dockerAuth") {
def image = docker.build("${reg}/${params.REPO}:${BUILD}", "-f ./Dockerfile .")
image.push()
}
def remote = [:]
remote.name = "machine"
withCredentials([string(credentialsId: "ssh_host", variable: "HOST")]) {
remote.host = "${HOST}"
}
withCredentials([usernamePassword(credentialsId: "ssh", usernameVariable: 'sshUser', passwordVariable: 'sshPass')]) {
remote.user = sshUser
remote.password = sshPass
}
remote.allowAnyHosts = true
echo "清除构建缓存"
sshCommand remote: remote, command: "sh -c \"docker rmi ${reg}/${params.REPO}:${BUILD} || true\";"
sshCommand remote: remote, command: "sh -c \"docker image prune -f || true\";";
sshCommand remote: remote, command: "sh -c \"docker builder prune -f || true\";";
echo "重新部署"
sshCommand remote: remote, command: "sh -c \"kubectl -n euler-copilot set image deployment/framework-deploy framework=${reg}/${params.REPO}:${BUILD}\";"
}