-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
151 lines (139 loc) · 3.92 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
pipeline {
agent {
kubernetes {
label 'hugo-agent'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: "jnlp"
volumeMounts:
- name: "volume-known-hosts"
mountPath: /home/jenkins/.ssh
- name: "volume-0"
mountPath: "/opt/tools"
readOnly: false
resources:
limits:
memory: "2Gi"
cpu: "1"
requests:
memory: "2Gi"
cpu: "1"
- name: hugo
image: eclipsemosaic/hugo:0.75
command:
- cat
tty: true
resources:
limits:
memory: "2Gi"
cpu: "1"
requests:
memory: "2Gi"
cpu: "1"
volumes:
- name: volume-known-hosts
configMap:
name: known-hosts
- name: "volume-0"
persistentVolumeClaim:
claimName: "tools-claim-jiro-mosaic"
readOnly: true
"""
}
}
parameters {
text(name: 'JAVADOC_VERSION', defaultValue: 'keep', description: 'Enter the MOSAIC version to generate JAVADOC from.')
}
environment {
PROJECT_NAME = "mosaic"
PROJECT_BOT_NAME = "MOSAIC Bot"
}
triggers { pollSCM('H/10 * * * *')
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
checkoutToSubdirectory('hugo')
disableConcurrentBuilds()
}
stages {
stage('Checkout www branch') {
steps {
dir('www') {
sshagent(['github-bot-ssh']) {
sh '''
git clone [email protected]:eclipse/mosaic.website.git .
git checkout www
'''
}
}
}
}
stage('Generate JavaDoc') {
when {
expression { params.JAVADOC_VERSION != 'keep' }
}
steps {
dir('mosaic') {
checkout scm: [$class: 'GitSCM',
userRemoteConfigs: [[url: 'https://github.com/eclipse/mosaic.git']],
branches: [[name: "refs/tags/${params.JAVADOC_VERSION}"]]
], poll: false
sh '/opt/tools/apache-maven/3.6.3/bin/mvn install -DskipTests=true -Dmaven.repo.local=.m2'
sh '/opt/tools/apache-maven/3.6.3/bin/mvn javadoc:javadoc javadoc:aggregate -DadditionalJOption=-Xdoclint:none -Dmaven.repo.local=.m2'
}
}
}
stage('Backup existing JavaDoc') {
when {
expression { params.JAVADOC_VERSION == 'keep' }
}
steps {
dir('mosaic') {
sh 'mkdir -p target/site/apidocs'
sh 'cp -Rvf ../www/java_docs/* target/site/apidocs/ || :'
}
}
}
stage('Build website from main with Hugo') {
when {
branch 'main'
}
steps {
container('hugo') {
dir('hugo') {
sh 'hugo -b https://www.eclipse.dev/${PROJECT_NAME}/'
}
}
}
}
stage('Push to www branch') {
when {
branch 'main'
}
steps {
sh 'rm -rf www/* && cp -Rvf hugo/public/* www/'
sh 'mkdir -p www/java_docs && cp -Rvf mosaic/target/site/apidocs/* www/java_docs/ || :'
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 'www.eclipse.org/${PROJECT_NAME}'"
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:www
else
echo "No change have been detected since last build, nothing to publish"
fi
'''
}
}
}
}
}
}