blob: 5fbd5873e5aa0a30f691b0ccebe40cfada6b5900 [file] [log] [blame]
Dean Birch62c4f082020-01-17 16:13:26 +00001#!/usr/bin/env groovy
2//-------------------------------------------------------------------------------
Paul Sokolovsky2ae6c742024-03-09 15:16:19 +07003// Copyright (c) 2020-2024, Arm Limited and Contributors. All rights reserved.
Dean Birch62c4f082020-01-17 16:13:26 +00004//
5// SPDX-License-Identifier: BSD-3-Clause
Dean Birch62c4f082020-01-17 16:13:26 +00006//-------------------------------------------------------------------------------
7
Dean Birchd0f9f8c2020-03-26 11:10:33 +00008@Library('trustedfirmware') _
9import org.trustedfirmware.Gerrit
10
Paul Sokolovsky2ae6c742024-03-09 15:16:19 +070011def nodeLabel = "docker-amd64-tf-m-jammy"
Dean Birchd0f9f8c2020-03-26 11:10:33 +000012
Antonio de Angelis7b7dad32025-07-05 21:54:02 +010013// Helpers
Xinyu Zhangab21b8d2021-04-30 14:15:09 +080014@NonCPS
Antonio de Angelis7b7dad32025-07-05 21:54:02 +010015def 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
21def 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
31def 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 Zhangab21b8d2021-04-30 14:15:09 +080039}
40
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080041timestamps {
Antonio de Angelis7b7dad32025-07-05 21:54:02 +010042 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 Komlevf84a5bb2025-07-09 10:12:12 +000050 }
51
Antonio de Angelis7b7dad32025-07-05 21:54:02 +010052 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 Komlevf84a5bb2025-07-09 10:12:12 +000061
Antonio de Angelis7b7dad32025-07-05 21:54:02 +010062 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 Komlevf84a5bb2025-07-09 10:12:12 +000092 } catch (Exception e) {
Antonio de Angelis7b7dad32025-07-05 21:54:02 +010093 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 Komlevf84a5bb2025-07-09 10:12:12 +0000101 }
Anton Komlevf84a5bb2025-07-09 10:12:12 +0000102 }
Dean Birch62c4f082020-01-17 16:13:26 +0000103}