-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline.code
More file actions
56 lines (56 loc) · 2.22 KB
/
Copy pathpipeline.code
File metadata and controls
56 lines (56 loc) · 2.22 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
pipeline {
agent any
parameters {
choice(name: 'CHOICES', choices: 'dev\nmaster', description: '请选择部署的环境')
}
// webhook方式触发流水线
// triggers {
// gitlab(triggerOnPush: true,
// triggerOnMergeRequest: true,
// branchFilterType: 'All',
// secretToken: "HbuJtMzbRTcVXenH4IRy")
// }
stages {
stage('拉代码') {
steps {
dir(env.WORKSPACE) {
checkout([$class: 'GitSCM', branches: [[name: "*/${params.CHOICES}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'github_user_login', url: 'https://github.com/niyang110/CI_CD_TEST.git']]])
}
}
}
stage('代码编译') {
steps {
dir(env.WORKSPACE) {
sh "echo 代码编译成功,这里仅仅是流程,假设这里是编译静态代码,把产出copy到相应的output目录去"
sh "cp -f index.html ansible/demo/file/index.html"
}
}
}
stage('部署dev环境') {
steps {
script {
if (params.CHOICES == 'dev') {
dir(env.WORKSPACE) {
sh "rm -rf /etc/ansible/roles/demo && cp -rf ansible/demo /etc/ansible/roles/demo"
sh "sed -i 's/@HOST_GROUP@/dev/g' ansible/deploy.yml"
sh "/usr/bin/ansible-playbook -i ansible/host ansible/deploy.yml"
}
}
}
}
}
stage('部署master环境') {
steps {
script {
if (params.CHOICES == 'master') {
dir(env.WORKSPACE) {
sh "rm -rf /etc/ansible/roles/demo && cp -rf ansible/demo /etc/ansible/roles/demo"
sh "sed -i 's/@HOST_GROUP@/master/g' ansible/deploy.yml"
sh "/usr/bin/ansible-playbook -i ansible/host ansible/deploy.yml"
}
}
}
}
}
}
}