forked from OPUS4/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
126 lines (107 loc) · 4.32 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
// Jenkinsfile for the framework
// Define the project name and the build type. A short build dispenses with coverage, since coverage is very time-consuming
def jobNameParts = JOB_NAME.tokenize('/') as String[]
def projectName = jobNameParts[0]
def buildType = "short"
// If the project has "night" in its name and the master branch or the development branch is present, the build is defined as a long build
if (projectName.contains('night') && (env.BRANCH_NAME == '4.7' || env.BRANCH_NAME == 'master')) {
buildType = "long"
}
pipeline {
/*
Agent (location where the pipeline is executed) is the docker file.
This must have root privileges, because MySQL and Solr must be installed.
Also, creating a docker on the server requires root privileges.
Furthermore, the docker socket of the server must be connected to the docker socket of the docker.
*/
agent { dockerfile {args "-u root -v /var/run/docker.sock:/var/run/docker.sock"}}
/*
A long build will not be built on every commit because of the long duration, but will be time-triggered.
Such a build is build once a day for the development branch and the master branch.
*/
triggers {
cron( buildType.equals('long') ? 'H 3 * * *' : '')
}
stages {
stage('Composer') {
steps {
// Update Operating system
sh 'sudo apt-get update'
// Install and update Composer. Additionally install dependencies of OPUS4-framework
sh 'curl -s http://getcomposer.org/installer | php && php composer.phar self-update && php composer.phar install'
}
}
stage('MySQL') {
steps {
sh 'sudo bash bin/install_mysql_docker.sh'
}
}
stage('Prepare Opus4') {
steps {
// Prepare OPUS4 with ant using standard passwords (only test-system)
sh 'ant prepare-workspace prepare-config create-database lint -DdbUserPassword=root -DdbAdminPassword=root'
// Install XDebug with Pecl -> Using apt-get would install a old version
sh 'pecl install xdebug-2.8.0 && echo "zend_extension=/usr/lib/php/20151012/xdebug.so" >> /etc/php/7.0/cli/php.ini'
sh 'chown -R opus4:opus4 .'
}
}
stage('Analyse') {
steps {
script{
sh 'php composer.phar analysis'
}
}
}
stage('Test') {
steps {
script{
sh 'ant create-database'
if (buildType == 'long'){
sh 'php composer.phar test-coverage'
} else {
sh 'php composer.phar test'
}
}
}
}
}
post {
always {
/*
For the cleanup the entire workspace is deleted.
This reduces the server load, since Jenkins does not track the workspaces unnecessarily.
It may be possible to turn off tracking, but I couldn't find an option.
Jenkins must have permissions to delete the workspaces.
*/
sh "chmod -R 777 ."
// Publishing test-results (unit-tests)
step([
$class: 'JUnitResultArchiver',
testResults: 'build/phpunit.xml'
])
// Publishing checkstyle-results (coding-style)
step([
$class: 'hudson.plugins.checkstyle.CheckStylePublisher',
pattern: 'build/checkstyle.xml'
])
// Publishing CPD-results (find duplicated code-fragments)
step([
$class: 'hudson.plugins.dry.DryPublisher',
pattern: 'build/pmd-cpd.xml'
])
// Publishing PMD-results (static codeanalysis)
step([
$class: 'hudson.plugins.pmd.PmdPublisher',
pattern: 'build/pmd.xml'
])
// Publishing coverage-report if exists
step([
$class: 'CloverPublisher',
cloverReportDir: 'build',
cloverReportFileName: 'clover.xml'
])
// Cleanup
step([$class: 'WsCleanup', externalDelete: 'rm -rf *'])
}
}
}