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}/" ''' } }