-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
127 lines (115 loc) · 3.87 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
#!/usr/bin/groovy
@Library(['github.com/indigo-dc/jenkins-pipeline-library@1.4.0']) _
pipeline {
agent {
label 'deep-oc'
}
stages {
stage('Fetch repository') {
steps {
checkout scm
}
}
stage('Generate Pelican site') {
when {
not { branch 'master' }
not { branch 'pelican' }
}
steps {
sh 'make html'
}
}
stage('Update submodules @deep-oc') {
when {
allOf {
branch 'pelican'
not { triggeredBy 'UpstreamCause' }
}
}
steps {
// Get last version of DEEP-OC modules
JenkinsBuildJob(
"Pipeline-as-code/deep-oc/master",
[booleanParam(name: 'disable_oc_build', value: true)])
}
}
stage('Generate markdown from applications metadata') {
when {
branch 'pelican'
}
steps {
iterateOverProjects()
sh 'git status --porcelain=v1'
sh 'git diff --diff-filter=M'
}
}
stage('Generate and publish Pelican site to Github Pages') {
when {
branch 'pelican'
}
steps {
withCredentials([usernamePassword(
credentialsId: "deephdc-bot",
usernameVariable: "GITHUB_USER",
passwordVariable: "GITHUB_TOKEN")]) {
sh 'git fetch origin master:master -f'
sh 'git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/deephdc/deephdc.github.io"'
sh 'make github'
}
}
}
}
}
void iterateOverProjects() {
subdir_name = 'deep-oc-subdir'
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [
[
$class: 'RelativeTargetDirectory',
relativeTargetDir: "$subdir_name"
],
[
$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: false,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false,
]
],
submoduleCfg: [],
userRemoteConfigs: [[url: 'https://github.com/deephdc/deep-oc']]]
)
dir(subdir_name) {
any_build_failure = false
data = sh(
script: 'git submodule | awk \'{print $2}\'',
returnStdout: true
).trim().split()
data.each{
repo_name = sh(returnStdout: true, script: "basename ${it}").trim()
dir(repo_name) {
try {
// TEST: Validate metadata according to DEEP schema
sh 'deep-app-schema-validator metadata.json'
// TEST: Search for non-ascii characters
sh 'python -c "open(\'metadata.json\').read().encode(\'utf8\')"'
// Generate markdown file from metadata
def markdown_file = [repo_name, 'md'].join('.').toLowerCase()
sh "${WORKSPACE}/metadata2md.py metadata.json --output-file ${WORKSPACE}/content/modules/${markdown_file}"
}
catch (e) {
echo "An error occurred while building DEEP module <${repo_name}>"
any_build_failure = true
}
}
}
}
if (any_build_failure) {
echo "There were errors building DEEP modules. Setting the build status as UNSTABLE"
currentBuild.result = 'UNSTABLE'
}
}