-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-pipeline.groovy
88 lines (73 loc) · 2.1 KB
/
deploy-pipeline.groovy
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Jenkins Release pipeline
Required non-default plugins:
1. HTTP Request
2. Pipeline Utility Steps
3. AnsiColor
4. Build Name and Description Setter
5. Ansible
Required parameters list:
1. NODE
2. VEEPEENET_VERSION
3. HOST
4. HOST_SSH_PORT
5. HOST_SSH_CRED
6. CHECK
7. REPO_CLONE_URL
8. REPO_BRANCH
*/
node {
cleanWs()
stage("Checks") {
requiredParametersNames = [
"NODE", "VEEPEENET_VERSION", "HOST", "HOST_SSH_PORT", "HOST_SSH_CRED", "REPO_CLONE_URL", "REPO_BRANCH"
]
undefinedParams = []
requiredParametersNames.each { paramName ->
if (!params[paramName]) {
undefinedParams << paramName
}
}
if (undefinedParams) {
error("Required params are undefined: $undefinedParams")
}
}
repoDir = "${pwd()}/veepeenet"
inventoryPath = "${pwd()}/inventory.ini"
deployPlaybookPath = "$repoDir/deploy-playbook.yml"
distribFilePath = "${pwd()}/veepeenet.tar.gz"
buildName "#$BUILD_NUMBER ${if (params.VEEPEENET_VERSION) params.VEEPEENET_VERSION else 'CUSTOM'}"
stage("Sources") {
dir(repoDir) {
log "Cloning $params.REPO_CLONE_URL, branch: $params.REPO_BRANCH"
git url: params.REPO_CLONE_URL, branch: params.REPO_BRANCH
log "Repository cloned"
}
}
stage("Prepare") {
log("Generating inventory.ini")
writeFile file: inventoryPath, text: params.HOST
log("inventory.ini generated")
}
stage("Deploy") {
ansiColor {
ansiblePlaybook(
playbook: deployPlaybookPath,
inventory: inventoryPath,
credentialsId: params.HOST_SSH_CRED,
disableHostKeyChecking: true,
extraVars: [
release_version: params.VEEPEENET_VERSION,
ansible_port:params.HOST_SSH_PORT
],
extras: "${if (params.CHECK) '--check' else ''}",
colorized: true
)
}
}
}
def log(message) {
timestamps {
echo "$message"
}
}