Skip to content

Commit 9189f3a

Browse files
committed
Add a post build stage
Add sbom sign job in post build stage Signed-off-by: Sophia Guo <[email protected]>
1 parent d07cc6a commit 9189f3a

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

pipelines/build/common/build_base_file.groovy

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,40 @@ class Builder implements Serializable {
747747

748748
return true
749749
}
750+
/*
751+
Call job to do post task. For now enable sbom sign
752+
*/
753+
def postStage() {
754+
context.stage('post-build') {
755+
//Job name need to discuss
756+
context.println "Post build - parallel post tasks, e.g. sbom sign"
757+
def postBuildJob = context.build job: 'Sophia_pipeline',
758+
parameters: [
759+
context.string(name: 'UPSTREAM_JOB_NAME', value: env.JOB_NAME),
760+
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${currentBuild.getNumber()}")
761+
]
762+
context.node('worker') {
763+
// Remove any previous workspace artifacts
764+
context.sh 'rm -rf *.json || true'
765+
context.copyArtifacts(
766+
projectName: 'Sophia_pipeline',
767+
selector: context.specific("${postBuildJob.getNumber()}"),
768+
filter: '*.json',
769+
fingerprintArtifacts: true,
770+
target: 'sbom/',
771+
flatten: true)
772+
773+
// Archive signed sbom in Jenkins
774+
try {
775+
context.timeout(time: pipelineTimeouts.ARCHIVE_ARTIFACTS_TIMEOUT, unit: 'HOURS') {
776+
context.archiveArtifacts artifacts: "sbom/*.json"
777+
}
778+
} catch (FlowInterruptedException e) {
779+
throw new Exception("[ERROR] Archive artifact timeout (${pipelineTimeouts.ARCHIVE_ARTIFACTS_TIMEOUT} HOURS) for Sophia_pipeline has been reached. Exiting...")
780+
}
781+
}
782+
}
783+
}
750784

751785
/*
752786
Call job to push artifacts to github. Usually it's only executed on a nightly build
@@ -927,7 +961,12 @@ class Builder implements Serializable {
927961
}
928962
}
929963
context.parallel jobs
930-
964+
965+
try {
966+
postStage()
967+
} catch (Exception e) {
968+
context.println(e.message)
969+
}
931970
// publish to github if needed
932971
// Don't publish release automatically
933972
if (publish && !release) {

tools/post-build/Jenkinsfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Build once a day
2+
CRON_SETTINGS = '''H H * * *'''
3+
NODE_LABEL = 'dockerBuild&&linux&&x64'
4+
5+
pipeline {
6+
agent none
7+
parameters {
8+
string(name: 'UPSTREAM_JOB_NAME', defaultValue: '', description: 'Pipeline job with sbom filesCompared nightly build job name')
9+
string(name: 'UPSTREAM_JOB_NUMBER', defaultValue: '', description: 'Pipeline job number')
10+
11+
}
12+
stages {
13+
stage('Post-Build') {
14+
parallel {
15+
stage('sbomSign') {
16+
agent {
17+
label NODE_LABEL
18+
}
19+
steps {
20+
sbomSign()
21+
}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
28+
def sbomSign() {
29+
cleanWs()
30+
docker.image('adoptopenjdk/centos7_build_image').inside {
31+
checkout scm
32+
checkout([$class: 'GitSCM', branches: [[name: 'post']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "sbomSign"]], submoduleCfg: [], userRemoteConfigs: [[url: "https://github.com/sophia-guo/openjdk-build.git"]]])
33+
copyArtifacts excludes: '**/OpenJDK*-sbom*metadata.json',
34+
filter: '**/OpenJDK*-sbom*.json',
35+
fingerprintArtifacts: true,
36+
flatten: true,
37+
projectName: "${params.UPSTREAM_JOB_NAME}",
38+
target: 'sbom/',
39+
selector: specific("${params.UPSTREAM_JOB_NUMBER}")
40+
script {
41+
dir("sbomSign/cyclonedx-lib") {
42+
sh label: 'build-sign-sbom', script: '''
43+
JAVA_HOME=/usr/lib/jvm/jdk-17 ant clean
44+
JAVA_HOME=/usr/lib/jvm/jdk-17 ant build-sign-sbom
45+
openssl genpkey -algorithm RSA -pass pass:test -outform PEM -out testPrivateFile -pkeyopt rsa_keygen_bits:2048
46+
openssl rsa -in testPrivateFile -passin pass:test -pubout -out publicPemFile
47+
'''
48+
}
49+
def sbomFiles = findFiles(glob: "**/OpenJDK*-sbom*.json")
50+
for (def sbomFile: sbomFiles) {
51+
def sbomFileName = sbomFile.path
52+
def classPath = "sbomSign/cyclonedx-lib/build/jar/*"
53+
sh label: 'sign-sbom', script: """
54+
/usr/lib/jvm/jdk-17/bin/java -cp "${classPath}" temurin.sbom.TemurinSignSBOM --signSBOM --jsonFile ${sbomFileName} --privateKeyFile ./sbomSign/cyclonedx-lib/testPrivateFile
55+
/usr/lib/jvm/jdk-17/bin/java -cp "${classPath}" temurin.sbom.TemurinSignSBOM --verifySignature --jsonFile ${sbomFileName} --publicKeyFile ./sbomSign/cyclonedx-lib/publicPemFile
56+
"""
57+
}
58+
}
59+
archiveArtifacts artifacts: "**/OpenJDK*-sbom*.json"
60+
}
61+
}

0 commit comments

Comments
 (0)