-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
79 lines (76 loc) · 2.79 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
70
71
72
73
74
75
76
77
78
79
def gitCommit(){
withCredentials([usernamePassword(credentialsId: "github-credential", passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
sh """
set +e
git status | grep vm-list.txt
if [ \$? -eq 0 ]; then
git remote -v
git remote remove origin
git remote add origin https://${USERNAME}:${PASSWORD}@github.com/shenxianpeng/vmm.git
git remote -v
git add $filePath
# if the file not change
git commit -m "add ${params.hostname} into vm-list.txt"
git push
fi
"""
}
}
pipeline{
agent {
label 'master'
}
environment {
GITHUB = credentials("github-credential")
}
parameters {
string name: 'hostname', defaultValue: "", description: 'Input your full hostname you want to check. example abc.company.com'
booleanParam(defaultValue: false, name: 'remove', description: 'If selected, means you want to remove above hostname')
}
triggers {
cron '0 15 * * 1-5' // run at every week day 15:00.
}
options {buildDiscarder(logRotator(numToKeepStr:'50'))}
stages{
stage("Checkout"){
steps{
checkout scm
}
}
stage("Start to check"){
steps{
script {
sh "chmod u+x vm-*.sh"
if (params.hostname.isEmpty()) {
// case 1: just run hostname in the list
sh "vm-check-main.sh ${GITHUB_USR} ${GITHUB_PSW} ${params.hostname}"
else if (params.hostname.endsWith(".com")) {
if (params.remove) {
// remove hostname from list, then run and commit into git.
sh "vm-check-main.sh ${GITHUB_USR} ${GITHUB_PSW} ${params.hostname} 1"
gitCommit("vm-list.txt", "remove ${params.hostname} from vm-list.txt")
} else {
// add hostname from the list, then run and commit into git.
sh "vm-check-main.sh ${GITHUB_USR} ${GITHUB_PSW} ${params.hostname}"
git.Commit("vm-list.txt", "add ${params.hostname} into vm-list.txt")
}
} else {
error 'your input hostname looks like not full name, plese double check.'
}
}
}
}
stage("Archive result"){
steps {
// save below files for user check
archiveArtifacts 'vm-check-result.log'
archiveArtifacts 'vm-list.txt'
}
}
}
post{
success {
cleanWs()
}
}
}