Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | //------------------------------------------------------------------------------- |
Paul Sokolovsky | 2ae6c74 | 2024-03-09 15:16:19 +0700 | [diff] [blame] | 3 | // Copyright (c) 2020-2024, Arm Limited and Contributors. All rights reserved. |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 4 | // |
| 5 | // SPDX-License-Identifier: BSD-3-Clause |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 6 | //------------------------------------------------------------------------------- |
| 7 | |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame] | 8 | @Library('trustedfirmware') _ |
| 9 | import org.trustedfirmware.Gerrit |
| 10 | |
Paul Sokolovsky | 2ae6c74 | 2024-03-09 15:16:19 +0700 | [diff] [blame] | 11 | def nodeLabel = "docker-amd64-tf-m-jammy" |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame] | 12 | |
Antonio de Angelis | 7b7dad3 | 2025-07-05 21:54:02 +0100 | [diff] [blame] | 13 | // Helpers |
Xinyu Zhang | ab21b8d | 2021-04-30 14:15:09 +0800 | [diff] [blame] | 14 | @NonCPS |
Antonio de Angelis | 7b7dad3 | 2025-07-05 21:54:02 +0100 | [diff] [blame] | 15 | def getUpstreamProjectName() { |
| 16 | def causes = manager.build.getAction(hudson.model.CauseAction.class)?.getCauses() |
| 17 | def upstreamCause = causes?.find { it instanceof hudson.model.Cause$UpstreamCause } |
| 18 | return upstreamCause?.upstreamProject |
| 19 | } |
| 20 | |
| 21 | def archiveRequired(String pattern) { |
| 22 | def matchedFiles = findFiles(glob: pattern) |
| 23 | if (matchedFiles.length > 0) { |
| 24 | echo "Archiving required files: ${pattern}" |
| 25 | archiveArtifacts artifacts: pattern, allowEmptyArchive: false |
| 26 | } else { |
| 27 | error "Required artifacts not found for pattern: ${pattern}" |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | def archiveOptional(String pattern) { |
| 32 | def matchedFiles = findFiles(glob: pattern) |
| 33 | if (matchedFiles.length > 0) { |
| 34 | echo "Archiving optional files: ${pattern}" |
| 35 | archiveArtifacts artifacts: pattern, allowEmptyArchive: false |
| 36 | } else { |
| 37 | echo "Optional artifacts missing for pattern: ${pattern} — skipping." |
| 38 | } |
Xinyu Zhang | ab21b8d | 2021-04-30 14:15:09 +0800 | [diff] [blame] | 39 | } |
| 40 | |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 41 | timestamps { |
Antonio de Angelis | 7b7dad3 | 2025-07-05 21:54:02 +0100 | [diff] [blame] | 42 | node(nodeLabel) { |
| 43 | stage("Init") { |
| 44 | cleanWs() |
| 45 | dir("tf-m-ci-scripts") { |
| 46 | tfgit.checkout_ci_scripts() |
| 47 | sh "git rev-parse --short HEAD" |
| 48 | sh "./clone.sh" |
| 49 | } |
Anton Komlev | f84a5bb | 2025-07-09 10:12:12 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Antonio de Angelis | 7b7dad3 | 2025-07-05 21:54:02 +0100 | [diff] [blame] | 52 | try { |
| 53 | stage("Build") { |
| 54 | if (env.CONFIG_NAME.contains("ARMCLANG")) { |
| 55 | withCredentials([string(credentialsId: 'ARMCLANG_UBL_CODE', variable: 'ARMCLANG_UBL_CODE')]) { |
| 56 | sh "tf-m-ci-scripts/jenkins/armclang-ubl.sh" |
| 57 | } |
| 58 | } |
| 59 | sh "tf-m-ci-scripts/run-build.sh" |
| 60 | } |
Anton Komlev | f84a5bb | 2025-07-09 10:12:12 +0000 | [diff] [blame] | 61 | |
Antonio de Angelis | 7b7dad3 | 2025-07-05 21:54:02 +0100 | [diff] [blame] | 62 | stage("Post") { |
| 63 | // Required artifacts (secure side) |
| 64 | def requiredSpePaths = [ |
| 65 | 'ci_build/spe/bin/**', |
| 66 | 'ci_build/spe/api_ns/bin/**', |
| 67 | 'ci_build/spe/api_ns/interface/**' |
| 68 | ] |
| 69 | requiredSpePaths.each { archiveRequired(it) } |
| 70 | |
| 71 | // Optional artifacts (non-secure side) |
| 72 | def optionalNspePaths = [ |
| 73 | 'ci_build/nspe/bin/**', |
| 74 | 'ci_build/nspe/*.bin' |
| 75 | ] |
| 76 | optionalNspePaths.each { archiveOptional(it) } |
| 77 | |
| 78 | // Handle upstream-specific artifacts |
| 79 | def upstreamProject = getUpstreamProjectName() |
| 80 | |
| 81 | if (upstreamProject == "tf-m-build-and-test") { |
| 82 | archiveRequired('ci_build/spe/build-spe/generated/**') |
| 83 | } |
| 84 | |
| 85 | if (upstreamProject == "tf-m-nightly-performance") { |
| 86 | sh "mkdir -p ${SHARE_FOLDER}/Memory_footprint/" |
| 87 | def output = sh(script: "python3 tf-m-ci-scripts/performance.py --generate-memory", returnStdout: true).trim() |
| 88 | println(output) |
| 89 | } |
| 90 | } |
| 91 | |
Anton Komlev | f84a5bb | 2025-07-09 10:12:12 +0000 | [diff] [blame] | 92 | } catch (Exception e) { |
Antonio de Angelis | 7b7dad3 | 2025-07-05 21:54:02 +0100 | [diff] [blame] | 93 | echo "Exception: ${e.getClass().getName()}: ${e.getMessage()}" |
| 94 | echo "Archiving all build files due to build error (to allow investigation)" |
| 95 | archiveArtifacts artifacts: 'ci_build/**', allowEmptyArchive: true |
| 96 | manager.buildFailure() |
| 97 | } finally { |
| 98 | def g = new Gerrit() |
| 99 | g.verifyStatusInWorkspace(currentBuild.result == 'SUCCESS' ? 1 : -1, env.CONFIG_NAME, 'build') |
| 100 | cleanWs() |
Anton Komlev | f84a5bb | 2025-07-09 10:12:12 +0000 | [diff] [blame] | 101 | } |
Anton Komlev | f84a5bb | 2025-07-09 10:12:12 +0000 | [diff] [blame] | 102 | } |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 103 | } |