@@ -27,7 +27,18 @@ phases: |
27 | 27 | build: |
28 | 28 | commands: |
29 | 29 | - VERSION_HASH="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)-$CODEBUILD_RESOLVED_SOURCE_VERSION" |
30 | | -# See https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html |
| 30 | + |
| 31 | + # Remove any old artifacts with the same commit ID. This allows CI to run more than once for the same commit |
| 32 | + - | |
| 33 | + aws codeartifact delete-package-versions --domain $DOMAIN \ |
| 34 | + --repository $REPOSITORY \ |
| 35 | + --format maven \ |
| 36 | + --namespace $NAMESPACE \ |
| 37 | + --package $PACKAGE \ |
| 38 | + --versions $VERSION_HASH \ |
| 39 | + --region $REGION; |
| 40 | +
|
| 41 | + # See https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html |
31 | 42 | - echo "Setting version in POM to $VERSION_HASH" |
32 | 43 | - mvn versions:set -DnewVersion="$VERSION_HASH" --no-transfer-progress |
33 | 44 | - echo "Version is now $(grep version pom.xml | head -n 1 | sed -n 's/[ \t]*<version>\(.*\)<\/version>/\1/p')" |
@@ -49,14 +60,5 @@ phases: |
49 | 60 | - | |
50 | 61 | if expr ${CODEBUILD_BUILD_SUCCEEDING} != 1; then |
51 | 62 | echo "An error occured while building and uploading $REPOSITORY." |
52 | | - echo "Did a previous build already upload $VERSION_HASH to $REPOSITORY?" |
53 | | - echo "Try deleting $VERSION_HASH from $REPOSITORY and restart" |
54 | | - echo "Delete Package Version Command \n |
55 | | - aws codeartifact delete-package-versions --domain $DOMAIN \ |
56 | | - --repository $REPOSITORY \ |
57 | | - --format maven \ |
58 | | - --namespace $NAMESPACE \ |
59 | | - --package $PACKAGE \ |
60 | | - --versions $VERSION_HASH \ |
61 | | - --region $REGION"; |
| 63 | + echo "Check logs above for error details." |
62 | 64 | fi |