-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
69 lines (69 loc) · 2.73 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
61
62
63
64
65
66
67
68
69
node('jenkins-test') {
stage('Change hosts') {
echo "1.Change hosts files"
sh 'echo "172.16.120.55 gitlab.liuxiang.com" >> /etc/hosts'
sh 'echo "172.16.120.44 harbor.liuxiang.com" >> /etc/hosts'
}
stage('Clone') {
echo "2.Clone Stage"
git branch: 'master', url: 'http://gitlab.liuxiang.com:13800/liuxiang/netdisk.git'
script {
build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
}
}
stage('Build') {
echo "3.Build Docker Image Stage"
sh "docker build -t registry.cn-hangzhou.aliyuncs.com/876500/netdisk:${build_tag} ."
}
stage('Push') {
echo "4.Push Docker Image Stage"
withCredentials([usernamePassword(credentialsId: 'login_aliyun', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) {
sh "docker login -u ${dockerHubUser} -p ${dockerHubPassword} registry.cn-hangzhou.aliyuncs.com"
sh "docker push registry.cn-hangzhou.aliyuncs.com/876500/netdisk:${build_tag}"
}
}
stage('Promote to develop') {
def userInput = input(
id: 'userInput',
message: 'Promote to develop?',
parameters: [
[
$class: 'ChoiceParameterDefinition',
choices: "YES\nNO",
name: 'Env'
]
]
)
echo "This is a deploy step to ${userInput}"
if (userInput == "YES") {
sh "sed -i 's/<BUILD_TAG>/${build_tag}/' ./deploy/develop.yaml"
sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' ./deploy/develop.yaml"
sh "kubectl apply -f ./deploy/develop.yaml --validate=false"
sh "kubectl apply -f ./deploy/develop_ingress.yaml --validate=false"
sh "kubectl get pods -n develop"
} else {
//exit
}
}
stage('Promote to production') {
def userInput = input(
id: 'userInput',
message: 'Promote to production?',
parameters: [
[
$class: 'ChoiceParameterDefinition',
choices: "YES\nNO",
name: 'Env'
]
]
)
echo "This is a deploy step to ${userInput}"
if (userInput == "YES") {
sh "sed -i 's/<BUILD_TAG>/${build_tag}/' ./develop/production.yaml"
sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' ./develop/production.yaml"
sh "kubectl apply -f ./develop/production.yaml --record --validate=false"
sh "kubectl apply -f ./develop/production_ingress.yaml --record --validate=false"
sh "kubectl get pods -n production"
}
}
}