|
| 1 | +pipeline { |
| 2 | + agent none |
| 3 | + |
| 4 | + options { |
| 5 | + timestamps() |
| 6 | + skipDefaultCheckout(true) |
| 7 | + parallelsAlwaysFailFast() |
| 8 | + } |
| 9 | + |
| 10 | + parameters { |
| 11 | + string(name: 'BRANCH_NAME', defaultValue: 'main', description: 'Branch to build') |
| 12 | + string(name: 'GIT_COMMIT', defaultValue: '', description: 'Commit SHA to build, optional') |
| 13 | + string(name: 'REPO_URL', defaultValue: 'https://github.com/star-bnl/star-sw.git', description: 'Repository URL') |
| 14 | + } |
| 15 | + |
| 16 | + environment { |
| 17 | + ARTIFACT_DIR = 'artifacts' |
| 18 | + BUILDKIT_STEP_LOG_MAX_SIZE = '10000000' |
| 19 | + } |
| 20 | + |
| 21 | + stages { |
| 22 | + stage('Build Docker Images') { |
| 23 | + matrix { |
| 24 | + agent any |
| 25 | + |
| 26 | + axes { |
| 27 | + axis { |
| 28 | + name 'STAR_BASE' |
| 29 | + values 'root5', 'root6' |
| 30 | + } |
| 31 | + axis { |
| 32 | + name 'COMPILER' |
| 33 | + values 'gcc485', 'gcc11' |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + stages { |
| 38 | + stage('Checkout') { |
| 39 | + steps { |
| 40 | + echo "PARAM_BRANCH_NAME=${params.BRANCH_NAME}" |
| 41 | + echo "PARAM_GIT_COMMIT=${params.GIT_COMMIT}" |
| 42 | + echo "PARAM_REPO_URL=${params.REPO_URL}" |
| 43 | + echo "JOB_NAME=${env.JOB_NAME}" |
| 44 | + echo "BUILD_NUMBER=${env.BUILD_NUMBER}" |
| 45 | + echo "BUILD_URL=${env.BUILD_URL}" |
| 46 | + echo "NODE_NAME=${env.NODE_NAME}" |
| 47 | + echo "WORKSPACE=${env.WORKSPACE}" |
| 48 | + echo "STAR_BASE=${env.STAR_BASE}" |
| 49 | + echo "COMPILER=${env.COMPILER}" |
| 50 | + checkout([ |
| 51 | + $class: 'GitSCM', |
| 52 | + branches: [[name: "*/${params.BRANCH_NAME}"]], |
| 53 | + userRemoteConfigs: [[ |
| 54 | + url: "${params.REPO_URL}", |
| 55 | + refspec: '+refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*' |
| 56 | + ]] |
| 57 | + ]) |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + stage('Checkout exact commit if provided') { |
| 62 | + when { |
| 63 | + expression { return params.GIT_COMMIT?.trim() } |
| 64 | + } |
| 65 | + steps { |
| 66 | + sh ''' |
| 67 | + set -euxo pipefail |
| 68 | + echo "Checking out exact commit: ${GIT_COMMIT}" |
| 69 | + git fetch --all --tags |
| 70 | + git checkout "${GIT_COMMIT}" |
| 71 | + git rev-parse HEAD |
| 72 | + ''' |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + stage('Inspect workspace') { |
| 77 | + steps { |
| 78 | + sh ''' |
| 79 | + set -euxo pipefail |
| 80 | + echo "=== Shell environment snapshot ===" |
| 81 | + env | sort |
| 82 | + echo "=== Key variables ===" |
| 83 | + echo "JOB_NAME=${JOB_NAME:-}" |
| 84 | + echo "BUILD_NUMBER=${BUILD_NUMBER:-}" |
| 85 | + echo "BUILD_URL=${BUILD_URL:-}" |
| 86 | + echo "NODE_NAME=${NODE_NAME:-}" |
| 87 | + echo "WORKSPACE=${WORKSPACE:-}" |
| 88 | + echo "GIT_URL=${GIT_URL:-}" |
| 89 | + echo "GIT_BRANCH=${GIT_BRANCH:-}" |
| 90 | + echo "BRANCH_NAME=${BRANCH_NAME:-}" |
| 91 | + echo "CHANGE_ID=${CHANGE_ID:-}" |
| 92 | + echo "CHANGE_BRANCH=${CHANGE_BRANCH:-}" |
| 93 | + echo "CHANGE_TARGET=${CHANGE_TARGET:-}" |
| 94 | + echo "GITHUB_REF=${GITHUB_REF:-}" |
| 95 | + echo "GITHUB_SHA=${GITHUB_SHA:-}" |
| 96 | + echo "PARAM_BRANCH_NAME=${BRANCH_NAME:-}" |
| 97 | + echo "PARAM_GIT_COMMIT=${GIT_COMMIT:-}" |
| 98 | + echo "PARAM_REPO_URL=${REPO_URL:-}" |
| 99 | + echo "STAR_BASE=${STAR_BASE:-}" |
| 100 | + echo "COMPILER=${COMPILER:-}" |
| 101 | + pwd |
| 102 | + ls -la |
| 103 | + echo "=== Git status ===" |
| 104 | + git status || true |
| 105 | + echo "=== Git remotes ===" |
| 106 | + git remote -v || true |
| 107 | + echo "=== Git HEAD ===" |
| 108 | + git rev-parse HEAD || true |
| 109 | + ''' |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + stage('Verify Docker') { |
| 114 | + steps { |
| 115 | + sh ''' |
| 116 | + set -euxo pipefail |
| 117 | + echo "ARTIFACT_DIR=${ARTIFACT_DIR}" |
| 118 | + echo "STAR_BASE=${STAR_BASE}" |
| 119 | + echo "COMPILER=${COMPILER}" |
| 120 | + echo "PATH=${PATH}" |
| 121 | + command -v docker |
| 122 | + docker --version |
| 123 | + docker info |
| 124 | + docker buildx version |
| 125 | + ''' |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + stage('Set up Docker Buildx') { |
| 130 | + steps { |
| 131 | + sh ''' |
| 132 | + set -euxo pipefail |
| 133 | + builder_name="star-sw-${BUILD_NUMBER}-${STAR_BASE}-${COMPILER}" |
| 134 | + echo "${builder_name}" > .buildx-builder-name |
| 135 | + docker buildx rm "${builder_name}" || true |
| 136 | + docker buildx create \ |
| 137 | + --name "${builder_name}" \ |
| 138 | + --driver docker-container \ |
| 139 | + --driver-opt "env.BUILDKIT_STEP_LOG_MAX_SIZE=${BUILDKIT_STEP_LOG_MAX_SIZE}" \ |
| 140 | + --use |
| 141 | + docker buildx inspect "${builder_name}" --bootstrap |
| 142 | + ''' |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + stage('Build Docker Image') { |
| 147 | + steps { |
| 148 | + sh ''' |
| 149 | + set -euxo pipefail |
| 150 | + builder_name="$(cat .buildx-builder-name)" |
| 151 | + starenv="${STAR_BASE}-${COMPILER}" |
| 152 | + image_tag="ghcr.io/star-bnl/star-sw-${starenv}" |
| 153 | + image_tar="${ARTIFACT_DIR}/star-sw-${starenv}.tar" |
| 154 | +
|
| 155 | + mkdir -p "${ARTIFACT_DIR}" |
| 156 | +
|
| 157 | + echo "=== Building ${image_tag} ===" |
| 158 | + docker buildx build \ |
| 159 | + --builder "${builder_name}" \ |
| 160 | + --progress plain \ |
| 161 | + --build-arg "starenv=${STAR_BASE}" \ |
| 162 | + --build-arg "compiler=${COMPILER}" \ |
| 163 | + --tag "${image_tag}" \ |
| 164 | + --output "type=docker,dest=${image_tar}" \ |
| 165 | + . |
| 166 | +
|
| 167 | + ls -lh "${image_tar}" |
| 168 | + ''' |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + stage('Archive Docker Image') { |
| 173 | + steps { |
| 174 | + archiveArtifacts artifacts: "artifacts/star-sw-${STAR_BASE}-${COMPILER}.tar", fingerprint: true |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + post { |
| 180 | + always { |
| 181 | + sh ''' |
| 182 | + set +e |
| 183 | + if [ -f .buildx-builder-name ]; then |
| 184 | + builder_name="$(cat .buildx-builder-name)" |
| 185 | + docker buildx rm "${builder_name}" || true |
| 186 | + fi |
| 187 | + ''' |
| 188 | + } |
| 189 | + } |
| 190 | + } |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + post { |
| 195 | + always { |
| 196 | + echo "Build finished: ${currentBuild.currentResult}" |
| 197 | + } |
| 198 | + } |
| 199 | +} |
0 commit comments