forked from Riverside-Software/sonar-openedge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
84 lines (79 loc) · 3.65 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
#!groovy
stage 'Build OpenEdge plugin'
node ('master') {
// Set job description with PR title
if (env.BRANCH_NAME.startsWith('PR')) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'GitHub-GQuerret', usernameVariable: 'GH_LOGIN', passwordVariable: 'GH_PASSWORD']]) {
def resp = httpRequest url: "https://api.github.com/repos/Riverside-Software/sonar-openedge/pulls/${env.BRANCH_NAME.substring(3)}", customHeaders: [[name: 'Authorization', value: "token ${env.GH_PASSWORD}"]]
def ttl = getTitle(resp)
def itm = getItem(env.BRANCH_NAME)
itm.setDisplayName("PR-${env.BRANCH_NAME.substring(3)} '${ttl}'")
}
}
gitClean()
checkout scm
withEnv(["PATH+MAVEN=${tool name: 'Maven 3', type: 'hudson.tasks.Maven$MavenInstallation'}/bin"]) {
if ("master" == env.BRANCH_NAME) {
sh "mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true"
} else {
sh "mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package -Dmaven.test.failure.ignore=true"
}
}
archiveArtifacts artifacts: 'openedge-plugin/target/sonar-openedge-plugin-*.jar', excludes: 'openedge-plugin/target/sonar-openedge-plugin-*-sources.jar'
step([$class: 'Publisher', reportFilenamePattern: '**/testng-results.xml'])
if ("master" == env.BRANCH_NAME) {
withEnv(["PATH+MAVEN=${tool name: 'Maven 3', type: 'hudson.tasks.Maven$MavenInstallation'}/bin"]) {
sh "mvn -Dsonar.host.url=http://sonar.riverside-software.fr sonar:sonar"
}
} else {
withEnv(["PATH+MAVEN=${tool name: 'Maven 3', type: 'hudson.tasks.Maven$MavenInstallation'}/bin"]) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'GitHub-GQuerret', usernameVariable: 'GH_LOGIN', passwordVariable: 'GH_PASSWORD']]) {
sh "mvn -Dsonar.host.url=http://sonar.riverside-software.fr -Dsonar.analysis.mode=issues -Dsonar.github.pullRequest=${env.BRANCH_NAME.substring(3)} -Dsonar.github.repository=Riverside-Software/sonar-openedge -Dsonar.github.oauth=${env.GH_PASSWORD} sonar:sonar"
}
}
}
}
@NonCPS
def getItem(branchName) {
Jenkins.instance.getItemByFullName("sonar-openedge/${branchName}")
}
@NonCPS
def getTitle(json) {
def slurper = new groovy.json.JsonSlurper()
def jsonObject = slurper.parseText(json.content)
jsonObject.title
}
// see https://issues.jenkins-ci.org/browse/JENKINS-31924
def gitClean() {
timeout(time: 60, unit: 'SECONDS') {
if (fileExists('.git')) {
echo 'Found Git repository: using Git to clean the tree.'
// The sequence of reset --hard and clean -fdx first
// in the root and then using submodule foreach
// is based on how the Jenkins Git SCM clean before checkout
// feature works.
if (isUnix()) {
sh 'git reset --hard'
} else {
bat 'git reset --hard'
}
// Note: -e is necessary to exclude the temp directory
// .jenkins-XXXXX in the workspace where Pipeline puts the
// batch file for the 'bat' command.
if (isUnix()) {
sh 'git clean -ffdx -e ".jenkins-*/"'
sh 'git submodule foreach --recursive git reset --hard'
sh 'git submodule foreach --recursive git clean -ffdx'
} else {
bat 'git clean -ffdx -e ".jenkins-*/"'
bat 'git submodule foreach --recursive git reset --hard'
bat 'git submodule foreach --recursive git clean -ffdx'
}
}
else
{
echo 'No Git repository found: using deleteDir() to wipe clean'
deleteDir()
}
}
}