forked from eclipse-4diac/4diac-website-hugo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
103 lines (97 loc) · 2.56 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
pipeline {
agent {
kubernetes {
label 'hugo-agent'
yaml """
apiVersion: v1
metadata:
labels:
run: hugo
name: hugo-pod
spec:
containers:
- name: jnlp
volumeMounts:
- mountPath: /home/jenkins/.ssh
name: volume-known-hosts
env:
- name: "HOME"
value: "/home/jenkins"
- name: hugo
image: eclipsecbi/hugo_extended:0.110.0
command:
- cat
tty: true
volumes:
- configMap:
name: known-hosts
name: volume-known-hosts
"""
}
}
environment {
PROJECT_NAME = "4diac" // must be all lowercase.
PROJECT_BOT_NAME = "4diac Website Bot" // Capitalize the name
PROJECT_GH_ORG = "eclipse-4diac" // e.g. eclipse-hono
PROJECT_WEBSITE_REPO = "4diac-website" // e.g. hono-website
}
triggers { pollSCM('H/10 * * * *')
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
checkoutToSubdirectory('hugo')
timeout(time: 60, unit: 'MINUTES')
}
stages {
stage('Update and fetch submodules') {
steps {
dir('hugo') {
sh 'git submodule update --init --recursive'
}
}
}
stage('Checkout www repo') {
steps {
dir('www') {
sshagent(['github-bot-ssh']) {
sh '''
git clone ssh://[email protected]/${PROJECT_GH_ORG}/${PROJECT_WEBSITE_REPO}.git .
git checkout master
'''
}
}
}
}
stage('Build website (main) with Hugo') {
steps {
container('hugo') {
dir('hugo') {
sh 'hugo -b https://eclipse.dev/${PROJECT_NAME}/'
}
}
}
}
stage('Push to master branch') {
steps {
sh 'rm -rf www/* && cp -Rvf hugo/public/* www/'
dir('www') {
sshagent(['github-bot-ssh']) {
sh '''
git add -A
if ! git diff --cached --exit-code; then
echo "Changes have been detected, publishing to repo '${PROJECT_GH_ORG}/${PROJECT_WEBSITE_REPO}'"
git config user.email "${PROJECT_NAME}[email protected]"
git config user.name "${PROJECT_BOT_NAME}"
git commit -m "Website build ${JOB_NAME}-${BUILD_NUMBER}"
git log --graph --abbrev-commit --date=relative -n 5
git push origin HEAD:master
else
echo "No changes have been detected since last build, nothing to publish"
fi
'''
}
}
}
}
}
}