This repository has been archived by the owner on Jul 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
120 lines (106 loc) · 3.91 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
final String PRETRONIC_CI_SSH_KEY_CREDENTIAL_ID = "1c1bd183-26c9-48aa-94ab-3fe4f0bb39ae"
final String GIT_TEMPLATE_SSH = "git@github.com:Pretronic/Pretronic-Dokumentation-Template.git"
final String GIT_DOCS_SSH = "git@github.com:Pretronic/Pretronic-Documentation.git"
final String CI_NAME = "PretronicCI"
final String CI_EMAIL = "ci@pretronic.net"
final String CNAME = "docs.pretronic.net"
final String PROJECT_NAME = "Pretronic-Documentation"
final String TEMPLATE_PROJECT_NAME = "Pretronic-Dokumentation-Template"
pipeline {
agent any
options {
buildDiscarder logRotator(numToKeepStr: '10')
}
stages {
stage('Install pip packages') {
steps {
script {
sh """
pip3 install mkdocs-material
pip install mkdocs-git-revision-date-plugin
pip install mkdocs-git-committers-plugin-2
"""
}
}
}
stage('Prepare directories') {
steps {
script {
sshagent([PRETRONIC_CI_SSH_KEY_CREDENTIAL_ID]) {
sh """
if [ -d "template" ]; then rm -Rf template; fi
mkdir template
if [ -d "build" ]; then rm -Rf build; fi
mkdir build
cd template/
git clone --single-branch --branch master ${GIT_TEMPLATE_SSH}
"""
}
}
}
}
stage('Merge template in projects') {
steps {
script {
dir('projects') {
def files = findFiles()
files.each{ file ->
if(file.directory) {
sh "cp ../template/${TEMPLATE_PROJECT_NAME}/* ${file.name}/ -r -n"
}
}
}
}
}
}
stage("Build mkdocs") {
steps {
script {
dir('projects') {
def files = findFiles()
files.each{ file ->
if(file.directory) {
sh "cd ${file.name} && mkdocs build"
}
}
}
}
}
}
stage("Deploy builds") {
steps {
script {
sshagent([PRETRONIC_CI_SSH_KEY_CREDENTIAL_ID]) {
sh """
git config --global user.name '$CI_NAME' -v
git config --global user.email '$CI_EMAIL' -v
"""
sh """
cd build/
git clone --single-branch --branch gh-pages ${GIT_DOCS_SSH}
cd ${PROJECT_NAME}/
rm -R ./*
echo ${CNAME} > CNAME
"""
dir('projects') {
def files = findFiles()
files.each{ file ->
if(file.directory) {
sh "mkdir ../build/${PROJECT_NAME}/${file.name} && cp ${file.name}/site/* ../build/${PROJECT_NAME}/${file.name}/ -r"
}
}
}
sh """
cd build/${PROJECT_NAME}/
cp home/* ./ -r
rm -R home/
git add . -v
git commit -m 'New mkdocs build' -v
git push origin HEAD:gh-pages -v
"""
}
}
}
}
}
}