-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJenkinsfile
88 lines (85 loc) · 3.43 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
@Library('jenkins-shared-libraries')
def REPO_NAME = 'carlspring/derby-maven-plugin'
def SERVER_ID = 'carlspring-oss-snapshots'
def SERVER_URL = 'https://dev.carlspring.org/nexus/content/repositories/carlspring-oss-snapshots/'
pipeline {
agent {
docker {
args '-v /tmp/.m2:/tmp/.m2'
image 'strongboxci/alpine:jdk8-mvn-3.5'
}
}
options {
timeout(time: 2, unit: 'HOURS')
disableConcurrentBuilds()
}
stages {
stage('Building...')
{
steps {
withMaven(maven: 'maven-3.5', mavenSettingsConfig: 'a5452263-40e5-4d71-a5aa-4fc94a0e6833', mavenLocalRepo: '/tmp/.m2')
{
sh "mvn -U clean install -Dmaven.test.failure.ignore=true"
}
}
}
stage('Code Analysis') {
steps {
withMaven(maven: 'maven-3.5', mavenSettingsConfig: 'a5452263-40e5-4d71-a5aa-4fc94a0e6833', mavenLocalRepo: '/tmp/.m2')
{
script {
if(env.BRANCH_NAME == 'master') {
withSonarQubeEnv('sonar') {
// requires SonarQube Scanner for Maven 3.2+
sh "mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar"
}
}
else {
if(env.BRANCH_NAME.startsWith("PR-"))
{
withSonarQubeEnv('sonar') {
def PR_NUMBER = env.CHANGE_ID
echo "Triggering sonar analysis in comment-only mode for PR: ${PR_NUMBER}."
sh "mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar" +
" -Psonar-github" +
" -Dsonar.github.repository=${REPO_NAME}" +
" -Dsonar.github.pullRequest=${PR_NUMBER}"
}
}
else
{
echo "This step is skipped for branches other than master or PR-*"
}
}
}
}
}
}
stage('Deploy') {
when {
expression { BRANCH_NAME == 'master' && (currentBuild.result == null || currentBuild.result == 'SUCCESS') }
}
steps {
script {
withMaven(maven: 'maven-3.5', mavenSettingsConfig: 'a5452263-40e5-4d71-a5aa-4fc94a0e6833', mavenLocalRepo: '/tmp/.m2')
{
sh "mvn deploy -Dmaven.test.skip=true -DaltDeploymentRepository=${SERVER_ID}::default::${SERVER_URL}"
}
}
}
}
}
post {
always {
// Email notification
script {
def email = new org.carlspring.jenkins.notification.email.Email()
if(BRANCH_NAME == 'master') {
email.sendNotification()
} else {
email.sendNotification(null, false, null, [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']])
}
}
}
}
}