standardjobs.groovy 2.49 KB
Newer Older
Ben Cooksley's avatar
Ben Cooksley committed
1
// Read the contents of the gathered-jobs.json file a step created for us previously
2
def jobsToParse = readFileFromWorkspace('gathered-jobs.json')
3
def knownJobs = new groovy.json.JsonSlurper().parseText( jobsToParse )
4

Ben Cooksley's avatar
Ben Cooksley committed
5
// Iterate over all of the known jobs and create the necessary platform files
6
knownJobs.each {
Ben Cooksley's avatar
Ben Cooksley committed
7
	// Create our job name
8 9 10 11 12
	def jobName = "${it.product}/${it.name}/${it.branchGroup} ${it.platform}"

	// Make sure the folders for this exist
	folder( "${it.product}" )
	folder( "${it.product}/${it.name}" )
13

Ben Cooksley's avatar
Ben Cooksley committed
14
	// Read in the necessary Pipeline template
15
	def pipelineTemplate = readFileFromWorkspace("${it.pipelineTemplate}")
Ben Cooksley's avatar
Ben Cooksley committed
16
	// Now we can construct our Pipeline script
17 18
	// We append a series of variables to the top of it to provide a variety of useful information to the otherwise templated script
	// These appended variables are what makes one build different to the next, aside from the template which was used
19
	def pipelineScript = """
20
		|def repositoryUrl = "${it.repositoryUrl}"
21 22
		|def browserUrl = "${it.browserUrl}"
		|def branchToBuild = "${it.branch}"
23
		|def productName = "${it.product}"
24 25 26
		|def projectName = "${it.name}"
		|def branchGroup = "${it.branchGroup}"
		|def currentPlatform = "${it.platform}"
27
		|def ciEnvironment = "${it.environment}"
28 29
		|def buildFailureEmails = "${it.buildFailureEmails}"
		|def unstableBuildEmails = "${it.unstableBuildEmails}"
30 31

		|${pipelineTemplate}""".stripMargin()
32

33
	// Actually create the job now
34
	pipelineJob( jobName ) {
35
		properties {
36 37
			// We don't want to keep build results forever
			// We'll set it to keep the last 25 builds and discard everything else
38 39 40 41
			buildDiscarder {
				strategy {
					logRotator {
						numToKeepStr("25")
42 43 44
						daysToKeepStr('')
						artifactDaysToKeepStr('')
						artifactNumToKeepStr('')
45 46 47
					}
				}
			}
48 49 50
			// We don't want to be building the same project more than once
			// This is to prevent one project hogging resources
			// And also has a practical component as otherwise an older build could finish afterwards and upload old build results
51 52 53
			disableConcurrentBuilds()
		}
		triggers {
54 55
			// We want to enable SCM Polling so that git.kde.org can tell Jenkins to look for changes
			// At the same time, we don't want Jenkins scanning for changes, so set the Polling specification to be empty so nothing gets scheduled
56
			pollSCM {
57
				scmpoll_spec('')
58 59 60
				ignorePostCommitHooks(false)
			}
		}
61
		// This is where the Pipeline script actually happens :)
62 63 64 65 66 67
		definition {
			cps {
				script( pipelineScript )
				sandbox()
			}
		}
68
	}
69
}