Skip to content

Commit 7048113

Browse files
Merged dspace-cris-2025_02_x into task/dspace-cris-2025_02_x/DSC-2699
2 parents 2f85df8 + 405c632 commit 7048113

File tree

1 file changed

+46
-18
lines changed

1 file changed

+46
-18
lines changed

bitbucket-pipelines.yml

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -266,38 +266,59 @@ definitions:
266266
- git commit -am "Enable test environment for ${BRANCH_NAME}" || echo "No changes to commit"
267267
- git push
268268

269-
- step: &find-and-invalidate-cloudfront-dev
270-
name: Invalidate CloudFront Dev Cache
269+
- step: &find-cloudfront-dev
270+
name: Find CloudFront Dev Cache
271271
image: amazon/aws-cli
272272
script:
273273
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_CF_KEY_ID
274274
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_CF_KEY
275275
- export AWS_DEFAULT_REGION=$AWS_REGION
276276
- export CLOUDFRONT_NAME=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
277277
- export CLOUDFRONT_DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Comment=='dev--${CLOUDFRONT_NAME}'].Id" --output text)
278-
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*" || echo "CloudFront distribution $CLOUDFRONT_DISTRIBUTION_ID not found — skipping invalidation."
278+
- echo "cloudfront_distribution=$CLOUDFRONT_DISTRIBUTION_ID" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
279+
output-variables:
280+
- cloudfront_distribution
279281

280-
- step: &find-and-invalidate-cloudfront-staging
281-
name: Invalidate CloudFront Staging Cache
282+
- step: &find-cloudfront-staging
283+
name: Find CloudFront Staging Cache
282284
image: amazon/aws-cli
283285
script:
284286
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_CF_KEY_ID
285287
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_CF_KEY
286288
- export AWS_DEFAULT_REGION=$AWS_REGION
287289
- export CLOUDFRONT_NAME=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
288290
- export CLOUDFRONT_DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Comment=='staging--${CLOUDFRONT_NAME}'].Id" --output text)
289-
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*" || echo "CloudFront distribution $CLOUDFRONT_DISTRIBUTION_ID not found — skipping invalidation."
291+
- echo "cloudfront_distribution=$CLOUDFRONT_DISTRIBUTION_ID" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
292+
output-variables:
293+
- cloudfront_distribution
290294

291-
- step: &find-and-invalidate-cloudfront-test
292-
name: Invalidate CloudFront Test Cache
295+
- step: &invalidate-cloudfront
296+
name: Invalidate CloudFront Cache
297+
image: amazon/aws-cli
298+
condition:
299+
state: cloudfront_distribution != ""
300+
script:
301+
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_CF_KEY_ID
302+
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_CF_KEY
303+
- export AWS_DEFAULT_REGION=$AWS_REGION
304+
- |
305+
if ! aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"; then
306+
echo "CloudFront invalidation failed for distribution ID: $CLOUDFRONT_DISTRIBUTION_ID"
307+
exit 1
308+
fi
309+
310+
- step: &find-cloudfront-test
311+
name: Find CloudFront Test Cache
293312
image: amazon/aws-cli
294313
script:
295314
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_CF_KEY_ID
296315
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_CF_KEY
297316
- export AWS_DEFAULT_REGION=$AWS_REGION
298317
- export CLOUDFRONT_NAME=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
299318
- export CLOUDFRONT_DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Comment=='test--${CLOUDFRONT_NAME}'].Id" --output text)
300-
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*" || echo "CloudFront distribution $CLOUDFRONT_DISTRIBUTION_ID not found — skipping invalidation."
319+
- echo "cloudfront_distribution=$CLOUDFRONT_DISTRIBUTION_ID" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
320+
output-variables:
321+
- cloudfront_distribution
301322

302323
- step: &check-branch-name-allowed
303324
name: Check allowed branch name
@@ -323,13 +344,15 @@ pipelines:
323344
- step: *angular-build
324345
- step: *build-and-push
325346
- step: *deploy-on-dev
326-
- step: *find-and-invalidate-cloudfront-dev
347+
- step: *find-cloudfront-dev
348+
- step: *invalidate-cloudfront
327349
deploy-on-staging:
328350
- step: *check-branch-name-allowed
329351
- step: *angular-build
330352
- step: *build-and-push
331353
- step: *deploy-on-staging
332-
- step: *find-and-invalidate-cloudfront-staging
354+
- step: *find-cloudfront-staging
355+
- step: *invalidate-cloudfront
333356
turn-on-dev:
334357
- step: *turn-on-dev
335358
turn-on-staging:
@@ -349,27 +372,32 @@ pipelines:
349372
- parallel: *parallel-run-tests
350373
- step: *build-and-push
351374
- step: *deploy-on-dev
352-
- step: *find-and-invalidate-cloudfront-dev
375+
- step: *find-cloudfront-dev
376+
- step: *invalidate-cloudfront
353377
- step: *deploy-on-staging
354-
- step: *find-and-invalidate-cloudfront-staging
355-
'prod/**':
378+
- step: *find-cloudfront-staging
379+
- step: *invalidate-cloudfront
380+
"prod/**":
356381
- step: *check-branch-name-allowed
357382
- step: *preliminary-operation
358383
- step: *angular-build
359384
- parallel: *parallel-run-tests
360385
- step: *build-and-push
361386
- step: *deploy-on-dev
362-
- step: *find-and-invalidate-cloudfront-dev
387+
- step: *find-cloudfront-dev
388+
- step: *invalidate-cloudfront
363389
- step: *deploy-on-staging
364-
- step: *find-and-invalidate-cloudfront-staging
365-
'test/**':
390+
- step: *find-cloudfront-staging
391+
- step: *invalidate-cloudfront
392+
"test/**":
366393
- step: *check-branch-name-allowed
367394
- step: *preliminary-operation
368395
- step: *angular-build
369396
- parallel: *parallel-run-tests
370397
- step: *build-and-push
371398
- step: *deploy-on-test
372-
- step: *find-and-invalidate-cloudfront-test
399+
- step: *find-cloudfront-test
400+
- step: *invalidate-cloudfront
373401

374402
pull-requests:
375403
'**':

0 commit comments

Comments
 (0)