-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
120 lines (104 loc) · 3.13 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Jekyll check pipeline for our documentation site.
*/
pipeline {
agent { label 'worker' }
options {
timeout(time: 30, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '5'))
}
stages {
/**
* Get environment statistics.
*/
stage('Stat') {
steps {
script {
sh('''
env
/snap/bin/hugo version
pygmentize -V
''')
}
}
}
/**
* Test and build.
*/
stage('Build') {
steps {
sh("/snap/bin/hugo")
}
}
/**
* Publish.
*/
stage('Publish') {
when {
expression {
env.BRANCH_NAME == 'master'
}
}
environment {
GITHUB = credentials('krotscheck_jenkins_github_credentials')
}
steps {
sh("""
# Go To Public folder
cd public
# Add changes to git.
git checkout master
git add .
# Commit changes.
git commit -m "Jenkins: Rebuilding site #${env.BUILD_NUMBER}"
# Push source and build repos.
git push https://${GITHUB_USR}:${GITHUB_PSW}@github.com/kangaroo-server/kangaroo-server.github.io.git master
""")
}
}
}
post {
/**
* When the build status changed, send the result.
*/
changed {
script {
def buildStatus = currentBuild.currentResult
def url = env.BUILD_URL, message, color
if (env.CHANGE_URL && buildStatus == 'SUCCESS') {
url = env.CHANGE_URL
}
switch (buildStatus) {
case 'FAILURE':
message = "Build <${url}|${env.JOB_NAME}> failed."
color = '#AA0000'
break
case 'SUCCESS':
message = "Build <${url}|${env.JOB_NAME}> passed."
color = '#00AA00'
break
case 'UNSTABLE':
default:
message = "Build <${url}|${env.JOB_NAME}> unstable."
color = '#FFAA00'
}
slackSend(
channel: '#build-notifications',
tokenCredentialId: 'kangaroo-server-slack-id',
teamDomain: 'kangaroo-server',
color: color,
message: message
)
}
}
/**
* Actions always to run at the end of a pipeline.
*/
always {
/**
* Delete everything, to keep track of disk size.
*/
cleanWs(deleteDirs: true)
}
}
}