-
Notifications
You must be signed in to change notification settings - Fork 21
/
Jenkinsfile
80 lines (73 loc) · 1.86 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
pipeline {
agent {
dockerfile {
dir '.jenkins'
filename 'Dockerfile.build'
}
}
environment {
HOME = "$WORKSPACE"
}
stages {
stage('Cleanup') {
steps {
sh "git clean -fdx"
}
}
stage('Prepare repository') {
steps {
sh """
git lfs pull
git submodule update --init --recursive
"""
}
}
stage ('Build') {
steps {
sh "./hugo.sh"
}
}
stage ('Generate gh-pages') {
steps {
sh """
# Generage gh-pages
git branch -fD gh-pages || true
git branch -rd origin/gh-pages || true
ghp-import -n public
"""
dir ("public") {
sh """
zip ../gh-pages.zip -r -q .
"""
}
}
}
stage ('Publish (master)') {
when {
branch 'master'
}
steps {
withCredentials([usernamePassword(credentialsId: 'github_bozaro_user', passwordVariable: 'GITHUB_TOKEN', usernameVariable: 'GITHUB_LOGIN')]) {
sh """
git push -qf https://\${GITHUB_LOGIN}:\${GITHUB_TOKEN}@github.com/bozaro/tech-db-lectures.git gh-pages
"""
}
}
}
stage ('Publish (branch)') {
when {
expression { BRANCH_NAME ==~ /(master|20\d\d-[12])/ }
}
steps {
sshagent(credentials: ['web-deploy']) {
sh 'rsync -e "ssh -o StrictHostKeyChecking=no" -rlvzc --no-owner --no-group --delete-after public/ [email protected]:tech-db-lectures/$BRANCH_NAME/'
}
}
}
}
post {
always {
archiveArtifacts artifacts: "*.zip", fingerprint: false
}
}
}