blob: 88d1af3db2694830f9ca674573ddd2af62ba4ec8 [file] [log] [blame]
#!/usr/bin/env groovy
//-------------------------------------------------------------------------------
// Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause
//
//-------------------------------------------------------------------------------
@NonCPS
def isPerPatchJob() {
def upstream_job = manager.build.getAction(hudson.model.CauseAction.class).getCauses()[0]
if (upstream_job instanceof hudson.model.Cause.UpstreamCause) {
def gp_causes = upstream_job.getUpstreamCauses()
if (gp_causes.size() > 0 && gp_causes[0] instanceof hudson.model.Cause.UpstreamCause) {
print("Grand-parent project cause: ")
println(gp_causes[0].upstreamProject)
if (gp_causes[0].upstreamProject.endsWith("tf-m-static")) {
return true
}
}
}
return false
}
def filterTestDevice() {
def device_type = env.DEVICE_FILTER
if (env.DEVICE_FILTER != "") {
return device_type
}
// For AN521 builds running per-patch (started by the tf-m-static job),
// run tests only on FVP to improve turnaround/performance.
// Skip tests on MUSCA B1 in per-patch for better performance.
if (isPerPatchJob()) {
if (env.TFM_PLATFORM == "arm/mps2/an521" || env.TFM_PLATFORM == "arm/musca_b1") {
device_type = "--fvp-only "
print("Run test cases only on FVP in tf-m-static.")
}
}
return device_type
}
def submitJobs(device_type) {
dir("tf-m-ci-scripts") {
def res = sh(script: """./lava_helper/lava_create_jobs.py \
--output-dir lava_jobs ${device_type} \
--jenkins-build-url ${env.BUILD_URL} \
--docker-prefix ${env.DOCKER_PREFIX} --license-variable "${env.LICENSE_VARIABLE}" \
--enable-code-coverage "${env.CODE_COVERAGE_EN}"
""", returnStdout: true).trim()
print(res)
job_ids = sh(script: """./lava_helper/lava_submit_jobs.py \
--lava-url ${env.LAVA_URL} --job-dir lava_jobs \
--lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} | egrep "^JOBS"
""", returnStdout: true).trim()
print("${job_ids}")
currentBuild.setDescription(job_ids)
}
}
timestamps {
node("docker-amd64-tf-m-bionic") {
stage("Init") {
cleanWs()
dir("tf-m-ci-scripts") {
checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
}
}
stage("LAVA") {
// Workaround for Groovy CPS idiosyncrasies. See e.g.
// https://blog.thesparktree.com/you-dont-know-jenkins-part-3#solutions
upstream_job = null
gp_causes = null
def device_type = filterTestDevice()
withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
print("Generating LAVA jobs...")
try {
submitJobs(device_type)
} catch (Exception ex) {
print("LAVA-Submit failed! Exception: ${ex}")
print("Try to submit again...")
submitJobs(device_type)
currentBuild.setDescription(currentBuild.getDescription() + " Submitted twice!")
}
}
}
stage("Post") {
archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_jobs/**', allowEmptyArchive: true
cleanWs()
}
}
}