1+ steps :
2+ # Step 1: Build Artifacts and Generate SBOM
3+ - name : ' maven:3.8-jdk-8'
4+ id : build-and-sbom
5+ entrypoint : ' mvn'
6+ env :
7+ - ' MAVEN_OPTS=-Xmx3200m'
8+ args :
9+ - -B
10+ - -V
11+ - -DskipTests
12+ - clean
13+ - package # Build and package
14+ - -P release
15+ - org.cyclonedx:cyclonedx-maven-plugin:2.7.10:makeAggregateBom # Generate SBOM
16+
17+ # Step 2: Prepare and Stage Artifacts for Secure Publishing
18+ - name : ' gcr.io/cloud-builders/gsutil'
19+ id : stage-for-secure-publishing
20+ entrypoint : ' bash'
21+ args :
22+ - -c
23+ - |
24+ set -ex
25+
26+ # Check if substitutions are provided
27+ if [[ -z "${_SECURE_PUBLISH_BUCKET_NAME}" || "${_SECURE_PUBLISH_BUCKET_NAME}" == "YOUR_SECURE_PUBLISH_BUCKET_NAME" ]]; then
28+ echo "ERROR: _SECURE_PUBLISH_BUCKET_NAME substitution is missing or not set."
29+ exit 1
30+ fi
31+ if [[ -z "${_APP_VERSION}" ]]; then
32+ echo "ERROR: _APP_VERSION substitution is missing."
33+ exit 1
34+ fi
35+
36+ SECURE_GCS_PATH="gs://${_SECURE_PUBLISH_BUCKET_NAME}"
37+ STAGING_DIR="/workspace/secure-staging"
38+ mkdir -p "$${STAGING_DIR}"
39+
40+ echo "Gathering Maven artifacts for Secure Publishing..."
41+ # Find all relevant artifacts from the build in the root target directory
42+ find /workspace/target -maxdepth 1 -type f \( -name "*.pom" -o -name "*.jar" \) ! -name "original-*.jar" ! -name "*-tests.jar" -exec cp {} "$${STAGING_DIR}/" \;
43+
44+ # Add the aggregate SBOM if it's at the root target
45+ if [ -f /workspace/target/bom.json ]; then
46+ cp /workspace/target/bom.json "$${STAGING_DIR}/bom.json"
47+ else
48+ echo "WARNING: bom.json not found in /workspace/target"
49+ fi
50+
51+ echo "Uploading artifacts to Secure Publishing bucket: $${SECURE_GCS_PATH}"
52+ # Check if there are files to upload
53+ if [ -n "$(ls -A "$${STAGING_DIR}")" ]; then
54+ gsutil -m cp -r "$${STAGING_DIR}/." "$${SECURE_GCS_PATH}/"
55+ else
56+ echo "No artifacts found in $${STAGING_DIR} to upload."
57+ exit 1
58+ fi
59+
60+ echo "Generating manifest.json"
61+ cd "$${STAGING_DIR}"
62+ printf '{\n "artifacts": [\n' > /workspace/manifest.json
63+ # escape double quotes in file names
64+ find . -type f -exec printf ' "%s",\n' {} \; | sed 's/"/\\"/g; s/^ "\\"/ "/' | sed '$ s/,$//' >> /workspace/manifest.json
65+ printf ' ]\n}\n' >> /workspace/manifest.json
66+ cd /workspace
67+ gsutil cp /workspace/manifest.json "$${SECURE_GCS_PATH}/manifest.json"
68+ echo "Secure Publishing staging complete."
69+
70+ options :
71+ requestedVerifyOption : VERIFIED
72+ logging : CLOUD_LOGGING_ONLY
73+ machineType : ' E2_HIGHCPU_32'
0 commit comments