From a6f3dd0b6e8ecdb2775ccd91f31dc2b098aa0780 Mon Sep 17 00:00:00 2001 From: Stephen Simpson Date: Tue, 16 Jun 2026 10:26:07 -0500 Subject: [PATCH] deploy: skip --delete on R2 sync when partial rebuild When EXISTING_VERSIONS is set, the build only produces HTML for a subset of versions and the bucket already contains the others. s5cmd sync with --delete would purge those existing keys. Omit --delete in that case and keep it for full rebuilds (EXISTING_VERSIONS empty). Assisted-by: Claude Opus 4 (Claude Code) --- Jenkinsfile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 75f33d8..34684d2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -141,14 +141,24 @@ docker run --rm \ string(credentialsId: 'r2-access-key-id', variable: 'AWS_ACCESS_KEY_ID'), string(credentialsId: 'r2-secret-access-key', variable: 'AWS_SECRET_ACCESS_KEY') ]) { + // When EXISTING_VERSIONS is set this is a partial rebuild, + // so omit --delete to preserve versions already in the bucket. sh ''' +if [ -n "${EXISTING_VERSIONS}" ]; then + DELETE_FLAG="" + echo "Partial rebuild (EXISTING_VERSIONS set) -- preserving existing objects." +else + DELETE_FLAG="--delete" + echo "Full rebuild -- bucket will be synced with --delete." +fi + docker run --rm \ -v "$(pwd)/html:/workspace/html" \ -e AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY \ peakcom/s5cmd:latest \ --endpoint-url "https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com" \ - sync --delete /workspace/html/ "s3://${R2_BUCKET_NAME}/" + sync ${DELETE_FLAG} /workspace/html/ "s3://${R2_BUCKET_NAME}/" ''' } }