Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | //------------------------------------------------------------------------------- |
Xinyu Zhang | be224f6 | 2021-02-03 17:57:38 +0800 | [diff] [blame] | 3 | // Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved. |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 4 | // |
| 5 | // SPDX-License-Identifier: BSD-3-Clause |
| 6 | // |
| 7 | //------------------------------------------------------------------------------- |
| 8 | |
Xinyu Zhang | be224f6 | 2021-02-03 17:57:38 +0800 | [diff] [blame] | 9 | @NonCPS |
| 10 | def getUpstreamJob() { |
| 11 | def cause = manager.build.getAction(hudson.model.CauseAction.class).getCauses() |
| 12 | return cause |
| 13 | } |
| 14 | |
Xinyu Zhang | 302b74d | 2021-11-03 14:53:44 +0800 | [diff] [blame] | 15 | def submitJobs(device_type, bl2_string, psa_string) { |
Xinyu Zhang | 4c0e140 | 2021-04-26 11:46:47 +0800 | [diff] [blame] | 16 | dir("tf-m-ci-scripts") { |
| 17 | def res = sh(script: """./lava_helper/lava_create_jobs.py \ |
Xinyu Zhang | 302b74d | 2021-11-03 14:53:44 +0800 | [diff] [blame] | 18 | --build-number ${env.BUILD_NUMBER} --output-dir lava_jobs ${device_type}\ |
Xinyu Zhang | 4c0e140 | 2021-04-26 11:46:47 +0800 | [diff] [blame] | 19 | --compiler ${env.COMPILER} --platform ${env.TARGET_PLATFORM} \ |
| 20 | ${bl2_string} ${psa_string} --build-type ${env.CMAKE_BUILD_TYPE} \ |
| 21 | --jenkins-build-url ${env.BUILD_URL} --proj-config ${env.PROJ_CONFIG} \ |
Leonardo Sandoval | 12fbb2f | 2021-04-15 14:36:09 -0500 | [diff] [blame] | 22 | --docker-prefix ${env.DOCKER_PREFIX} --license-variable "${env.LICENSE_VARIABLE}" \ |
| 23 | --enable-code-coverage "${env.CODE_COVERAGE_EN}" |
Xinyu Zhang | 4c0e140 | 2021-04-26 11:46:47 +0800 | [diff] [blame] | 24 | """, returnStdout: true).trim() |
| 25 | print(res) |
| 26 | job_ids = sh(script: """./lava_helper/lava_submit_jobs.py \ |
| 27 | --lava-url ${env.LAVA_URL} --job-dir lava_jobs \ |
| 28 | --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} | egrep "^JOBS" |
| 29 | """, returnStdout: true).trim() |
Paul Sokolovsky | 79b9d37 | 2022-01-05 14:03:14 +0300 | [diff] [blame] | 30 | print("${job_ids}") |
Xinyu Zhang | 4c0e140 | 2021-04-26 11:46:47 +0800 | [diff] [blame] | 31 | currentBuild.setDescription(job_ids) |
| 32 | } |
| 33 | } |
| 34 | |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 35 | timestamps { |
| 36 | node("docker-amd64-tf-m-bionic") { |
| 37 | stage("Init") { |
| 38 | cleanWs() |
| 39 | dir("tf-m-ci-scripts") { |
| 40 | checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]]) |
| 41 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 42 | } |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 43 | stage("LAVA") { |
Xinyu Zhang | 302b74d | 2021-11-03 14:53:44 +0800 | [diff] [blame] | 44 | def device_type = "" |
Paul Sokolovsky | 64b7cc9 | 2022-03-28 20:55:43 +0300 | [diff] [blame^] | 45 | |
| 46 | // For builds running per-patch (started by the tf-m-static job), |
| 47 | // run tests only on physical boards to improve turnaround/performance. |
| 48 | def upstream_job = getUpstreamJob()[0] |
| 49 | if (upstream_job instanceof hudson.model.Cause.UpstreamCause) { |
| 50 | def gp_causes = upstream_job.getUpstreamCauses() |
| 51 | if (gp_causes.size() > 0 && gp_causes[0] instanceof hudson.model.Cause.UpstreamCause) { |
| 52 | print("Grand-parent project cause: ") |
| 53 | println(gp_causes[0].upstreamProject) |
| 54 | if (gp_causes[0].upstreamProject.endsWith("tf-m-static")) { |
| 55 | device_type = "--physical-board-only " |
| 56 | print("Run test cases only on physical boards in tf-m-static.") |
| 57 | } |
| 58 | } else { |
| 59 | println("No grand-parent project cause.") |
| 60 | } |
Leonardo Sandoval | 66eed7a | 2021-12-03 10:33:31 -0600 | [diff] [blame] | 61 | } |
Paul Sokolovsky | 64b7cc9 | 2022-03-28 20:55:43 +0300 | [diff] [blame^] | 62 | // Workaround for Groovy CPS idiosyncrasies. See e.g. |
| 63 | // https://blog.thesparktree.com/you-dont-know-jenkins-part-3#solutions |
| 64 | upstream_job = null |
| 65 | gp_causes = null |
Xinyu Zhang | be224f6 | 2021-02-03 17:57:38 +0800 | [diff] [blame] | 66 | |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 67 | withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) { |
| 68 | print("Generating LAVA jobs...") |
| 69 | def bl2_string = "" |
| 70 | def psa_string = "" |
| 71 | if (env.BL2.equals("True")) { |
| 72 | bl2_string = "--bl2" |
| 73 | } |
| 74 | // work around this string containing quotes? |
| 75 | if (env.PSA_API_SUITE != "") { |
| 76 | psa_string = "--psa-api-suite ${env.PSA_API_SUITE}" |
| 77 | } |
| 78 | try { |
Xinyu Zhang | 302b74d | 2021-11-03 14:53:44 +0800 | [diff] [blame] | 79 | submitJobs(device_type, bl2_string, psa_string) |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 80 | } catch (Exception ex) { |
| 81 | print("LAVA-Submit failed! Exception: ${ex}") |
| 82 | print("Try to submit again...") |
Xinyu Zhang | 302b74d | 2021-11-03 14:53:44 +0800 | [diff] [blame] | 83 | submitJobs(device_type, bl2_string, psa_string) |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 84 | currentBuild.setDescription(currentBuild.getDescription() + " Submitted twice!") |
| 85 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 86 | } |
| 87 | } |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 88 | stage("Post") { |
| 89 | archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_jobs/**', allowEmptyArchive: true |
| 90 | cleanWs() |
| 91 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 92 | } |
| 93 | } |