@@ -414,25 +414,61 @@ integration-test:
414414 expire_in: 30 days
415415
416416# Integration Tests - Cleanup stacks
417- # integration-cleanup-stacks:
418- # stage: integration-tests
419- # tags: [" arch:amd64" ]
420- # image: $ {CI_DOCKER_TARGET_IMAGE}:$ {CI_DOCKER_TARGET_VERSION}
421- # when: always
422- # rules:
423- # - when: always
424- # needs:
425- # - integration-test
426- # variables:
427- # IDENTIFIER: integration
428- # {{ with $environment := (ds " environments" ).environments.sandbox }}
429- # before_script:
430- # - EXTERNAL_ID_NAME= {{ $environment .external_id }} ROLE_TO_ASSUME= {{ $environment .role_to_assume }} AWS_ACCOUNT= {{ $environment .account }} source .gitlab /scripts/get_secrets.sh
431- # - curl -fsSL https://deb.nodesource.com /setup_20.x | bash -
432- # - apt-get install -y nodejs
433- # - cd integration-tests
434- # {{ end }}
435- # script:
436- # - echo " Destroying CDK stacks with identifier ${IDENTIFIER}..."
437- # - npx cdk destroy " IntegrationTests-$IDENTIFIER-*" --force || echo " Failed to destroy some stacks, but continuing..."
417+ integration-cleanup-stacks:
418+ stage: integration-tests
419+ tags: [" arch:amd64" ]
420+ image: $ {CI_DOCKER_TARGET_IMAGE}:$ {CI_DOCKER_TARGET_VERSION}
421+ when: always
422+ rules:
423+ - when: always
424+ needs:
425+ - integration-test
426+ variables:
427+ IDENTIFIER: $ {CI_COMMIT_SHORT_SHA}
428+ {{ with $environment := (ds " environments" ).environments.sandbox }}
429+ before_script:
430+ - EXTERNAL_ID_NAME= {{ $environment .external_id }} ROLE_TO_ASSUME= {{ $environment .role_to_assume }} AWS_ACCOUNT= {{ $environment .account }} source .gitlab /scripts/get_secrets.sh
431+ - curl -fsSL https://deb.nodesource.com /setup_20.x | bash -
432+ - apt-get install -y nodejs
433+ - cd integration-tests
434+ {{ end }}
435+ script:
436+ - echo " Destroying CDK stacks with identifier ${IDENTIFIER}..."
437+ - npx cdk destroy " integ-$IDENTIFIER-*" --force || echo " Failed to destroy some stacks, but continuing..."
438+
439+ # Integration Tests - Cleanup layer
440+ integration-cleanup-layer:
441+ stage: integration-tests
442+ tags: [" arch:amd64" ]
443+ image: $ {CI_DOCKER_TARGET_IMAGE}:$ {CI_DOCKER_TARGET_VERSION}
444+ when: always
445+ rules:
446+ - when: always
447+ needs:
448+ - integration-cleanup-stacks
449+ variables:
450+ IDENTIFIER: $ {CI_COMMIT_SHORT_SHA}
451+ {{ with $environment := (ds " environments" ).environments.sandbox }}
452+ before_script:
453+ - EXTERNAL_ID_NAME= {{ $environment .external_id }} ROLE_TO_ASSUME= {{ $environment .role_to_assume }} AWS_ACCOUNT= {{ $environment .account }} source .gitlab /scripts/get_secrets.sh
454+ {{ end }}
455+ script:
456+ - echo " Deleting integration test layer with identifier ${IDENTIFIER}..."
457+ - |
458+ LAYER_NAME= " Datadog-Extension-${IDENTIFIER}"
459+ echo " Looking for layer: ${LAYER_NAME}"
460+
461+ # Get all versions of the layer
462+ VERSIONS= $ (aws lambda list-layer-versions --layer-name " ${LAYER_NAME}" --query 'LayerVersions[*].Version ' --output text --region us-east-1 2>/dev/null || echo " " )
463+
464+ if [ -z " $VERSIONS" ]; then
465+ echo " No versions found for layer ${LAYER_NAME}"
466+ else
467+ echo " Found versions: ${VERSIONS}"
468+ for VERSION in $VERSIONS ; do
469+ echo " Deleting ${LAYER_NAME} version ${VERSION}..."
470+ aws lambda delete-layer-version --layer-name " ${LAYER_NAME}" --version-number " ${VERSION}" --region us-east-1 || echo " Failed to delete version ${VERSION}, continuing..."
471+ done
472+ echo " Successfully deleted all versions of ${LAYER_NAME}"
473+ fi
438474
0 commit comments