Skip to content
Snippets Groups Projects
Commit b724ab8b authored by Jonas Karlsson's avatar Jonas Karlsson
Browse files

Add Jenkinsfile

parent c77181b9
No related branches found
No related tags found
No related merge requests found
def parseLanceBotCommand(decodedString) {
return decodedString.split('\n').last().toLowerCase().replace("lancelotnext:","lancebotnext:").split('lancebotnext:').last().trim()
}
def base64Decode(encodedString) {
byte[] decoded = encodedString.decodeBase64()
String decode = new String(decoded)
return decode
}
def collectGerritParams() {
def params = []
env.getEnvironment().each { name, value ->
if (name.startsWith("GERRIT_")) {
params.add(string(name: "$name", value: "$value"))
}
}
return params
}
def printEnvironment() {
env.getEnvironment().each { name, value ->
println "${name}: ${value}"
}
}
def getValidTargets() {
return ["linux-opengl", "linux-vulkan", "mac-metal",
"imx8-opengl", "windows-d3d11", "windows-d3d12",
"windows-opengl"]
}
def lancebotUsageString() {
def allTargets = getValidTargets()
allTargets.add("fast (linux-opengl, mac-metal, windows-d3d12)")
allTargets.add("full (all targets)")
def str = ""
str += "Usage:\n"
str += "> lancebotnext: test TARGETS\n\n"
str += "Where TARGETS is a space separated list of target platforms to test on. "
str += "Valid targets are:\n> " + allTargets.join("\n> ") + "\n\n"
str += "For more information, see https://wiki.qt.io/Lancelot_Graphics_Testing\n"
return str
}
def lancebotFooter() {
def str = "\n\n- - - - - - - -\n"
str += "\n"
str += "Type 'lancebotnext: help' for LanceBot usage instructions.\n"
return str
}
def getTargetsMessage(targets) {
def str = "Running tests on targets: \n\n"
for (target in targets) {
str += " • " + target + "\n"
}
return str
}
def sendGerritMessage(msg) {
gerritReview labels: [Verified: 0], message: (msg)
}
def sendGerritMessageWithFooter(msg) {
sendGerritMessage(msg + "\nBuild URL: ${BUILD_URL}\n" + lancebotFooter())
}
def sendGerritMessageWithFooterAndFail(msg) {
sendGerritMessageWithFooter(msg)
error(msg)
}
def isQtEmployee() {
return "${GERRIT_EVENT_ACCOUNT_EMAIL}".endsWith("@qt.io")
}
def isQtDevBranch() {
return "${GERRIT_BRANCH}" == "dev" || "${GERRIT_BRANCH}".startsWith("6.")
}
def extractLancelotURL(str) {
def url = str.findAll(/http:\/\/lancelot\.intra\.qt\.io.*\.html/)[0]
return url ? url.replace("http://lancelot.intra.qt.io", "https://testresults.qt.io/lancebot") : ""
}
pipeline {
agent {
node {
label 'master-test'
}
}
stages {
stage('All') {
steps {
script {
def decoded = base64Decode("${GERRIT_EVENT_COMMENT_TEXT}")
println decoded
def args = parseLanceBotCommand(decoded).split(' ')
echo "Do Build for ${GERRIT_REFSPEC}"
println 'LanceBot args: ' + args
if (!(args[0] in ["test", "help"])) {
def error_msg = "Error: Invalid argument '" + args[0]+ "'\n"
sendGerritMessageWithFooterAndFail(error_msg)
}
if (args[0] == "help") {
sendGerritMessage(lancebotUsageString())
return
}
if (args.size() == 1) {
def error_msg = "Error: No targets specified.\n"
sendGerritMessageWithFooterAndFail(error_msg)
return
}
def targets = []
def validTargets = getValidTargets()
if (args.size() > 1) {
def i = 1
while (i < args.size()) {
def arg = args[i]
if (arg == "fast") {
targets.add("linux-opengl")
targets.add("mac-metal")
targets.add("windows-d3d12")
} else if (arg == "full") {
targets = validTargets
} else if (arg in validTargets) {
targets.add(arg)
} else {
def error_msg = "Error: Invalid target '${arg}'\n"
sendGerritMessageWithFooterAndFail(error_msg)
}
i = i + 1
}
}
targets = targets.unique(false)
if (targets.isEmpty()) {
def error_msg = "Error: No targets found.\n"
sendGerritMessageWithFooterAndFail(error_msg)
}
if (!isQtEmployee()) {
def error_msg = "Error: runs may currently only be triggered by TQtC employees.\n"
sendGerritMessageWithFooterAndFail(error_msg)
}
if (!isQtDevBranch()) {
def error_msg = "Error: can only test changes on Qt 6 branches.\n"
sendGerritMessageWithFooterAndFail(error_msg)
}
sendGerritMessageWithFooter(getTargetsMessage(targets))
def allResults = "Testing finished.\n\n"
def jobs = [:]
def publishReport = false
targets.every {
def jobId = it
def (platform, backend) = it.split("-")
jobs[jobId] = {
def params = collectGerritParams()
def jobName = ["mac" : "LanceBot6OnRequestMac",
"linux" : "LanceBot6OnRequestLinux",
"imx8" : "LanceBot6OnRequestLinux",
"windows" : "LanceBot6OnRequestWindows"][platform]
params.add(string(name: "LB_RHI_BACKEND", value: backend))
if (platform == "imx8") {
params.add(string(name: "LB_PLATFORM", value: "imx8qm-mek"))
}
def jobBuild = build job: "${jobName}", parameters: params, propagate: false, wait: true
def jobResult = jobBuild.getResult()
def jobLog = jobBuild.rawBuild.getLog(10000).join('\n')
def url = extractLancelotURL(jobLog)
def didTestRun = jobLog.lines().findAll { it.contains("Finished testing of") }.size() > 0
def resultMsg = ""
if (jobLog.contains("LanceBotFinishedOK")) {
resultMsg = "✅ Test OK (${jobId}): ${url}"
} else if (!didTestRun) {
resultMsg = " ❌ Test FAIL (${jobId}): Could not run"
} else if (url) {
resultMsg = " ❌ Test FAIL (${jobId}): ${url}"
} else if (jobLog == "") {
resultMsg = " ❌ Test FAIL (${jobId}): Could not get log"
} else if (jobLog.contains("Lancelot test FAILED")) {
resultMsg = " ❌ Test FAIL (${jobId}): Lancelot test failed"
} else if (jobLog.contains("ninja: build stopped")) {
resultMsg = " ❌ Test FAIL (${jobId}): Build failed"
} else if (!jobLog.contains("LanceBotFinishedOK")) {
resultMsg = " ❌ Test FAIL (${jobId}): Lancelot error"
} else {
resultMsg = " ❌ Test FAIL (${jobId}): Unknown error"
}
allResults += resultMsg + "\n"
publishReport = publishReport || !url.isEmpty();
}
}
parallel jobs
// Publish report only if some test failed
if (publishReport) {
build job: 'Publish_LanceBot_Report'
}
sendGerritMessageWithFooter(allResults)
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment