SUSEQt5.11.template 11.2 KB
Newer Older
1 2 3
// Provisionally mark the build as successful
currentBuild.result = 'SUCCESS'

4
// Request a node to be allocated to us
5
node( currentPlatform ) {
6 7 8 9
// We want Timestamps on everything
timestamps {
	// We want to catch any errors that occur to allow us to send out notifications (ie. emails) if needed
	catchError {
10 11
		// First Thing: Checkout Sources
		stage('Checkout Sources') {
12

13 14 15
			// Actual Application Sources
			checkout changelog: true, poll: true, scm: [
				$class: 'GitSCM',
16 17
				branches: [[name: branchToBuild]],
				browser: [$class: 'CGit', repoUrl: browserUrl],
18
				extensions: [[$class: 'CloneOption', timeout: 120]],
19
				userRemoteConfigs: [[url: repositoryUrl]]
20 21 22 23 24 25 26
			]

			// Our CI scripts
			checkout changelog: false, poll: false, scm: [
				$class: 'GitSCM',
				branches: [[name: 'master']],
				extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'ci-tooling/']],
27
				userRemoteConfigs: [[url: 'https://anongit.kde.org/sysadmin/ci-tooling']]
28 29
			]

30 31 32 33 34 35 36 37
			// Projects metadata and next generation dependency metadata
			checkout changelog: false, poll: false, scm: [
				$class: 'GitSCM',
				branches: [[name: 'master']],
				extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'ci-tooling/repo-metadata/']],
				userRemoteConfigs: [[url: 'https://anongit.kde.org/sysadmin/repo-metadata']]
			]

38 39 40 41
			// Dependency Metadata
			checkout changelog: false, poll: false, scm: [
				$class: 'GitSCM',
				branches: [[name: 'master']],
42
				extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'ci-tooling/kde-build-metadata/']],
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
				userRemoteConfigs: [[url: 'https://anongit.kde.org/kde-build-metadata']]
			]

			// KApiDox: For api.kde.org metadata extraction
			checkout changelog: false, poll: false, scm: [
				$class: 'GitSCM',
				branches: [[name: 'master']],
				extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'ci-tooling/kapidox/']],
				userRemoteConfigs: [[url: 'https://anongit.kde.org/kapidox']]
			]

			// kde-dev-scripts: For packager metadata extraction
			checkout changelog: false, poll: false, scm: [
				$class: 'GitSCM',
				branches: [[name: 'master']],
				extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'ci-tooling/kde-dev-scripts/']],
				userRemoteConfigs: [[url: 'https://anongit.kde.org/kde-dev-scripts']]
			]

		}

		// Now Prepare to Build: Get the dependencies ready
		stage('Setup Dependencies') {
			// Now we can determine what our dependencies are
			// Then update to the latest version of the dependencies available from the master server
			// Finally extract all of those dependencies in turn into the given 'installTo' directory
69
			sh "python3 -u ci-tooling/helpers/prepare-dependencies.py --product ${productName} --project ${projectName} --branchGroup ${branchGroup} --environment ${ciEnvironment} --platform ${currentPlatform} --installTo '$HOME/install-prefix/'"
70 71 72 73 74
		}

		// Now we can configure our build
		stage('Configuring Build') {
			// This is delegated through a helper script to handle minor special cases like inSourceBuilds, non-CMake build systems, etc
75
			sh "python3 -u ci-tooling/helpers/configure-build.py --product ${productName} --project ${projectName} --branchGroup ${branchGroup} --platform ${currentPlatform} --installTo '$HOME/install-prefix/'"
76 77 78 79 80
		}

		// Finally we can build it! (Once again, through a helper)
		stage('Compiling') {
			// We use a helper here so we can determine the appropriate number of CPUs (-j) to build with
81
			sh "python3 -u ci-tooling/helpers/compile-build.py --product ${productName} --project ${projectName} --branchGroup ${branchGroup} --platform ${currentPlatform} --usingInstall '$HOME/install-prefix/'"
82 83
		}

84 85 86 87 88 89 90 91 92 93
		// Now we can run our tests
		stage('Running Tests') {
			// Run the unit tests for this project
			// Tests are run in a basic environment (X, DBus)
			sh "python3 -u ci-tooling/helpers/run-tests.py --product ${productName} --project ${projectName} --branchGroup ${branchGroup} --platform ${currentPlatform} --usingInstall '$HOME/install-prefix/'"

			// Collect our results
			junit allowEmptyResults: true, testResults: 'JUnitTestResults.xml'
		}

94 95 96 97
		// Now ensure that it installs....
		stage('Installing') {
			// The helper ensures that DESTDIR and INSTALL_ROOT are set to 'divertTo'
			// This allows us to capture the install at the next stage for later reuse in the Setup Dependencies step
98
			sh "python3 -u ci-tooling/helpers/install-build.py --product ${productName} --project ${projectName} --branchGroup ${branchGroup} --platform ${currentPlatform} --installTo '$HOME/install-prefix/' --divertTo '$WORKSPACE/install-divert/'"
99 100 101 102 103 104 105 106
		}

		// Looks like it built okay - let's capture this for later use
		// We'll also take the opportunity to extract metadata from CMake used by packagers and api.kde.org
		stage('Capturing Installation') {
			// First we create a tar archive of the installation which was diverted
			// Then we upload a copy of that to the master server and have it publish the new archive
			// Finally to save bandwidth our copy of the tar archive is moved to our local cache for reuse on later builds on this node
107
			sh "python3 -u ci-tooling/helpers/capture-install.py --product ${productName} --project ${projectName} --branchGroup ${branchGroup} --environment ${ciEnvironment} --platform ${currentPlatform} --divertedTo '$WORKSPACE/install-divert/' --installedTo '$HOME/install-prefix/'"
108 109

			// Now we extract the CMake metadata and upload that to the appropriate hosts
110
			sh "python3 -u ci-tooling/helpers/extract-cmake-dependency-metadata.py --product ${productName} --project ${projectName} --branchGroup ${branchGroup} --platform ${currentPlatform} --usingInstall '$HOME/install-prefix/'"
111
			sh "python3 -u ci-tooling/helpers/generate-dependency-diagram-data.py --product ${productName} --project ${projectName} --branchGroup ${branchGroup} --platform ${currentPlatform} --usingInstall '$HOME/install-prefix/'"
112 113 114 115 116
		}

		// Final thing to do: some code quality checks
		stage('Checking Code Quality') {

117
			// Perform Appstream Compliance Checks
118
			sh "python3 -u ci-tooling/helpers/check-appstream-compliance.py --product ${productName} --project ${projectName} --branchGroup ${branchGroup} --platform ${currentPlatform} --usingInstall '$HOME/install-prefix/' --withDiverted '$WORKSPACE/install-divert/'"
119

120 121 122
			// Gather ABI Reference information for later checking
			sh """
				curl '$BUILD_URL/consoleText' -o currentBuildLog.txt
123
				python3 -u ci-tooling/helpers/create-abi-dump.py --project ${projectName} --branchGroup ${branchGroup} --platform ${currentPlatform} --buildLog currentBuildLog.txt --environment production --usingInstall '$HOME/install-prefix/' || true
124 125
			"""

126 127
			// Save the ABI build logs to review if necessary
			archiveArtifacts artifacts: 'logs/*/*/log.txt', onlyIfSuccessful: false, allowEmptyArchive: true
128 129
			// Save the input for ACC for building abi dumps locally
			archiveArtifacts artifacts: 'acc/*.xml', onlyIfSuccessful: false, allowEmptyArchive: true
130

131 132 133 134 135 136
			// Now perform the ABI Compatibility checks
			// This tool will produce reports stored at compat_reports/ which we will also need to capture
			sh """
				python3 -u ci-tooling/helpers/check-abi.py --project ${projectName} --branchGroup ${branchGroup} --platform ${currentPlatform} --environment production || true
			"""
			// Save the ABI Compatibility reports for developers to review if necessary
137
			archiveArtifacts artifacts: 'compat_reports/*_compat_report.html', onlyIfSuccessful: false, allowEmptyArchive: true
138

139 140 141
			// Save the ABI Compatibility results yaml file
			archiveArtifacts artifacts: 'abi-compatibility-results.yaml', onlyIfSuccessful: false, allowEmptyArchive: true

142 143 144
			// Platform Enablement Checks
			// Frameworks have a metadata file which specifies the platforms it supports and should be built on
			// This check compares that metadata file against the records held by the CI system 
145
			sh """
146
				touch PlatformCheckOutput.txt
147 148
				if [[ -e metainfo.yaml ]]; then python3 ci-tooling/helpers/check-platform.py '$WORKSPACE/metainfo.yaml' &> PlatformCheckOutput.txt; fi
			"""
149 150 151 152 153 154 155 156 157 158 159 160

			// If the platform check indicates there are missing platforms then we should flag the build as unstable
			// We start this process by reading the output of the check command
			def platformCheckResult = readFile "${env.WORKSPACE}/PlatformCheckOutput.txt"
			// Then we check to see if it had anything in it - it will be empty if everything is okay
			if( platformCheckResult != '' ) {
				// If it does, then mark the build as unstable
				currentBuild.result = 'UNSTABLE'
				// We also print the check results so it can be examined easily
				echo platformCheckResult
			}

161 162 163
			// cppcheck is not supported by Pipeline at the moment, so we don't run that for now
			// See https://issues.jenkins-ci.org/browse/JENKINS-35096

164
			// Perform Cobertura Processing
165 166 167 168
			// First, run the LCov extraction
			sh "python3 -u ci-tooling/helpers/extract-lcov-results.py --product ${productName} --project ${projectName} --branchGroup ${branchGroup} --platform ${currentPlatform}"

			// Collect the results from the LCov extraction
169 170 171
			step([
				$class: 'CoberturaPublisher',
				autoUpdateHealth: false, autoUpdateStability: false,
172
				coberturaReportFile: 'CoberturaLcovResults.xml',
173 174 175 176 177 178
				failNoReports: false, failUnhealthy: false, failUnstable: false,
				maxNumberOfBuilds: 0,
				onlyStable: false,
				zoomCoverageChart: false
			])

179
			// Scan the logs and publish a warnings report
180
			warnings consoleParsers: [[parserName: 'GNU Make + GNU C Compiler (gcc)'], [parserName: 'Appstreamercli']], excludePattern: "/tmp/**|/home/jenkins/workspace/**/build/**|/usr/include/**"
181 182 183

		}

184 185 186 187 188
	}

	// Let's determine if we need to send out notifications
	// What happened in our previous build?
	def previousResult = currentBuild.previousBuild?.result
189 190
	// If our condition has changed, is FAILURE or UNSTABLE then we want to send an email
	if( previousResult != currentBuild.result || currentBuild.result == 'FAILURE' || currentBuild.result == 'UNSTABLE' ) {
191 192 193 194 195 196 197 198 199 200
		// Start constructing the list of our recipients
		// At this point we can only be either a failure or an unstable build, so notify those who have requested unstable build notifications
		def mailTo = [ unstableBuildEmails ]

		// If the build was a solid failure (either now or previously) then notify those who want to know about failures only
		if( previousResult == 'FAILURE' || currentBuild.result == 'FAILURE' ) {
			// Add them to the list
			mailTo << buildFailureEmails
		}

201 202
		// If someone kicked this job off, they're presumably interested as well
		mailTo << emailextrecipients( [[$class: 'RequesterRecipientProvider']] )
203 204 205
		// We always want to notify our dashboard as well
		mailTo << "kde-dashboard@kde.org"

206 207 208 209 210 211 212
		// Finalise the list of recipients
		mailTo = mailTo.join(',')

		// Send the email now
		emailext(
			to: mailTo,
			body: '${JELLY_SCRIPT,template="html_gmail"}',
213
			mimeType: 'text/html',
214
			subject: 'KDE CI: ${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}!', 
215
			attachLog: false
216
		)
217
	}
218 219 220 221 222 223 224

	// IRC Notifications are currently not supported by Pipeline
	// See https://issues.jenkins-ci.org/browse/JENKINS-33922
	// We can probably workaround this using Pursuivant and the emails Jenkins sends out
	// This would allow subscribing to build notifications for IRC channels in much the same way one subscribes for Commits and Bugzilla changes

}
225
}