forked from jenkins-khan/jenkins-php-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
81 lines (76 loc) · 2.79 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
/* groovylint-disable */
void setBuildStatus(String message, String state) {
step([
$class: 'GitHubCommitStatusSetter',
reposSource: [$class: 'ManuallyEnteredRepositorySource', url: 'https://github.com/ooobii/jenkins-php-api'],
contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: 'build'],
errorHandlers: [[$class: 'ChangingBuildStatusErrorHandler', result: 'UNSTABLE']],
statusResultSource: [ $class: 'ConditionalStatusResultSource', results: [[$class: 'AnyBuildResult', message: message, state: state]] ]
])
}
void setLintStatus(String message, String state) {
step([
$class: 'GitHubCommitStatusSetter',
reposSource: [$class: 'ManuallyEnteredRepositorySource', url: 'https://github.com/ooobii/jenkins-php-api'],
contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: 'lint'],
errorHandlers: [[$class: 'ChangingBuildStatusErrorHandler', result: 'UNSTABLE']],
statusResultSource: [ $class: 'ConditionalStatusResultSource', results: [[$class: 'AnyBuildResult', message: message, state: state]] ]
])
}
pipeline {
agent { label 'linux' }
stages {
stage('Clone Repository') {
steps {
checkout([$class: 'GitSCM',
branches: [[name: "${GIT_BRANCH}"]],
extensions: [[$class: 'WipeWorkspace']],
userRemoteConfigs: [[url: '[email protected]:ooobii/jenkins-php-api.git']]
])
}
}
stage('Test Code Syntax') {
steps {
script {
try {
sh 'find ./src -name "*.php" -print0 | xargs -0 -n1 -P8 php -l'
setLintStatus('Syntax OK', 'SUCCESS')
} catch (Exception e) {
setLintStatus('Bad Syntax', 'FAILURE')
}
}
}
}
stage('Install Composer') {
steps {
sh '''
curl -sS https://getcomposer.org/installer -o composer-setup.php
mkdir composer
php composer-setup.php --install-dir=./composer --filename=composer
rm -rf composer-setup.php
'''
}
}
stage('Install Composer Pkgs') {
steps {
sh './composer/composer install --dev'
}
}
stage('Remove Composer') {
steps {
sh 'rm -rf ./composer'
}
}
}
post {
success {
setBuildStatus('Build Successful', 'SUCCESS')
}
failure {
setBuildStatus('Failure', 'FAILURE')
}
unstable {
setBuildStatus('Unstable', 'UNSTABLE')
}
}
}