create_review_job.groovy 2.4 KB
Newer Older
1
// Overall configuration
2 3
// As developers might be posting reviews for master or stable branches, we'll build against master
// While not perfect, this is the best solution we have for now
4 5 6 7
def branchGroup      = "kf5-qt5"
def ciEnvironment    = "production"

// Read in our variables, as we'll need to know what job we are creating...
8
def productName      = "${PRODUCT_NAME}"
9 10 11 12 13 14 15 16 17 18 19 20
def reviewID         = "${DIFF_ID}"
def reviewPHID       = "${PHID}"
def reviewStagingURL = "${STAGING_URI}"
def reviewStagingRef = "${STAGING_REF}"

// Determine which repository we have here
def projectName = reviewStagingURL.tokenize('/').last()

// Create a name for this job
def jobName = "Reviews/${reviewID}"

// Read in the necessary Pipeline template
21
def pipelineTemplate = readFileFromWorkspace("pre-review/review-build.template")
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

// Now we can construct our Pipeline script
// 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
def pipelineScript = """
	|def repositoryUrl = "${reviewStagingURL}"
	|def branchToBuild = "${reviewStagingRef}"
	|def productName = "${productName}"
	|def projectName = "${projectName}"
	|def branchGroup = "${branchGroup}"
	|def ciEnvironment = "${ciEnvironment}"

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

// Actually create the job now
pipelineJob( jobName ) {
Ben Cooksley's avatar
Ben Cooksley committed
38 39 40 41 42 43
	// In order to be able to report back to PHabricator, we'll need to know a few things
	// Like the Differential ID number (we technically already do, but the Phabricator plugin expects to see it as a parameter)
	parameters {
		stringParam('DIFF_ID')
		stringParam('PHID')
	}
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
	properties {
		// We don't want to keep build results forever
		// We'll set it to keep the last 25 builds and discard everything else
		buildDiscarder {
			strategy {
				logRotator {
					numToKeepStr("5")
					daysToKeepStr('')
					artifactDaysToKeepStr('')
					artifactNumToKeepStr('')
				}
			}
		}
		// 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
		disableConcurrentBuilds()
	}
	// This is where the Pipeline script actually happens :)
	definition {
		cps {
			script( pipelineScript )
			sandbox()
		}
	}
}