-
Notifications
You must be signed in to change notification settings - Fork 317
Expand file tree
/
Copy pathJenkinsfile
More file actions
144 lines (124 loc) · 5.54 KB
/
Jenkinsfile
File metadata and controls
144 lines (124 loc) · 5.54 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
def boolean onlyDocumentationFilesChangedIn(String workDirectory) {
if (!env.CHANGE_TARGET) {
echo "CHANGE_TARGET not set. Skipping check"
return false
}
def changedFiles = sh(script: "cd ${workDirectory} && git diff --name-only origin/${env.CHANGE_TARGET} origin/${env.BRANCH_NAME}", returnStdout: true).trim().split("\n")
echo "Changed files: ${changedFiles}" // Debug
return changedFiles && changedFiles.every { it.endsWith(".md") || it.endsWith(".txt") }
}
node {
properties([
disableConcurrentBuilds(abortPrevious: true),
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '1', daysToKeepStr: '', numToKeepStr: '3')),
gitLabConnection('gitlab.eclipse.org'),
[$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false],
[$class: 'JobLocalConfiguration', changeReasonComment: '']
])
deleteDir()
stage('Preparation') {
dir("kura") {
checkout scm
sh "touch /tmp/isJenkins.txt"
}
}
// Skip build if only documentation files (i.e. *.md and *.txt) have changed
if (onlyDocumentationFilesChangedIn("kura")) {
echo "Skipping build for documentation changes"
currentBuild.result = 'SUCCESS'
return
}
stage('Build target-platform') {
timeout(time: 1, unit: 'HOURS') {
dir("kura") {
withMaven(jdk: 'temurin-jdk21-latest', maven: 'apache-maven-3.9.9', options: [artifactsPublisher(disabled: true)]) {
sh "mvn -f target-platform/pom.xml clean install -Pno-mirror -Pcheck-exists-plugin"
}
}
}
}
stage('Build core') {
timeout(time: 2, unit: 'HOURS') {
dir("kura") {
withMaven(jdk: 'temurin-jdk21-latest', maven: 'apache-maven-3.9.9', options: [artifactsPublisher(disabled: true)]) {
sh "mvn -f kura/pom.xml -Dsurefire.rerunFailingTestsCount=3 clean install -Pcheck-exists-plugin"
}
}
}
}
stage('Build distrib') {
timeout(time: 1, unit: 'HOURS') {
dir("kura") {
withMaven(jdk: 'temurin-jdk21-latest', maven: 'apache-maven-3.9.9', options: [artifactsPublisher(disabled: true)]) {
sh "mvn -f kura/distrib/pom.xml clean install"
}
}
}
}
stage('Generate test reports') {
dir("kura") {
junit 'kura/test/*/target/surefire-reports/*.xml'
}
}
stage ("Deploy on Nexus") {
// Call uploadPackages only if we are on the default branch,
// if we have DEB packages to upload and if the user has set the pushArtifacts parameter to true
if (env.BRANCH_IS_PRIMARY) {
echo "Uploading DEB packages..."
def distribPom = readMavenPom file: 'kura/kura/distrib/pom.xml'
def repoDistribution = distribPom.properties['kura.repo.distribution']
def repoModule = distribPom.properties['kura.repo.module']
def nexusUtils = load 'kura/.jenkins/nexusUtils.groovy'
nexusUtils.uploadPackages(repoDistribution, repoModule)
} else {
echo "Skipping DEB upload"
Utils.markStageSkippedForConditional(STAGE_NAME)
}
}
stage('Archive .deb artifacts') {
dir("kura") {
archiveArtifacts artifacts: 'kura/distrib/**/target/*.deb', onlyIfSuccessful: true
}
}
stage('Sonar') {
timeout(time: 2, unit: 'HOURS') {
dir("kura") {
withMaven(jdk: 'temurin-jdk21-latest', maven: 'apache-maven-3.9.9', options: [artifactsPublisher(disabled: true)]) {
withSonarQubeEnv(credentialsId: 'sonarcloud-token') {
// Check if on primary branch
def analysisParameters = ""
if (env.CHANGE_ID) {
analysisParameters = "-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.key=${env.CHANGE_ID}"
} else {
analysisParameters = "-Dsonar.branch.name=${env.BRANCH_NAME}"
}
sh """
mvn -f kura/pom.xml org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
-Dmaven.test.failure.ignore=true \
-Dsonar.organization=eclipse \
-Dsonar.host.url=${SONAR_HOST_URL} \
-Dsonar.java.binaries='target/' \
${analysisParameters} \
-Dsonar.core.codeCoveragePlugin=jacoco \
-Dsonar.projectKey=org.eclipse.kura:kura \
-Dsonar.exclusions=test/**/*,**/*.xml,**/*.yml,test-util/**/* \
-Dsonar.test.exclusions=**/*
"""
}
}
}
}
}
stage('quality-gate') {
// Sonar quality gate
timeout(time: 30, unit: 'MINUTES') {
withCredentials([string(credentialsId: 'sonarcloud-token', variable: 'SONARCLOUD_TOKEN')]) {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to sonar quality gate failure: ${qg.status}"
}
}
}
}
}