AWS CodeBuild throws an error "CLIENT_ERROR Message: no matching artifact paths found

0

Report this ad

0

AWS CodeBuild throws an error "CLIENT_ERROR Message: no matching artifact paths found".

I'm trying to build a docker app using CodeCommit repository, Build phase seems to be passing without problems, but there is some issue with the artifact file path.

This is the link, I have referred https://youtu.be/MDMH_XXDbrI Timestamp: 48:18 to 56:24

Here is my buildspec:

version: 0.2

phases:

  pre_build:

  commands:

      - echo Logging in to Amazon ECR...

      - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com

      - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME

      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)

      - IMAGE_TAG=${COMMIT_HASH:=latest}

  build:

   commands:

      - echo Build started on `date`

      - echo Building the Docker image...
          
      - docker build -t $REPOSITORY_URI:latest .

      - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG

  post_build:

   commands:

      - echo Build completed on `date`

      - echo Pushing the Docker image...

      - docker push $REPOSITORY_URI:latest

      - docker push $REPOSITORY_URI:$IMAGE_TAG

      - echo Writing image definitions file...

      - printf '[{"name":"%s","imageUri":"%s"}]' "$IMAGE_REPO_NAME" "$REPOSITORY_URI:$IMAGE_TAG" > imagedefinitions.json

artifacts:

  files: imagedefinitions.json

Here is the build log:

[Container] 2023/05/06 06:40:30 Phase complete: PRE_BUILD State: SUCCEEDED

[Container] 2023/05/06 06:40:30 Phase context status code:  Message: 

[Container] 2023/05/06 06:40:30 Entering phase BUILD

[Container] 2023/05/06 06:40:30 Phase complete: BUILD State: SUCCEEDED

[Container] 2023/05/06 06:40:30 Phase context status code:  Message: 

[Container] 2023/05/06 06:40:30 Entering phase POST_BUILD

[Container] 2023/05/06 06:40:30 Phase complete: POST_BUILD State: SUCCEEDED

[Container] 2023/05/06 06:40:30 Phase context status code:  Message: 

[Container] 2023/05/06 06:40:30 Expanding base directory path: .

[Container] 2023/05/06 06:40:30 Assembling file list

[Container] 2023/05/06 06:40:30 Expanding .

[Container] 2023/05/06 06:40:30 Expanding file paths for base directory .

[Container] 2023/05/06 06:40:30 Assembling file list

[Container] 2023/05/06 06:40:30 Expanding imagedefinitions.json

[Container] 2023/05/06 06:40:30 Skipping invalid file path imagedefinitions.json

[Container] 2023/05/06 06:40:30 Phase complete: UPLOAD_ARTIFACTS State: FAILED

[Container] 2023/05/06 06:40:30 Phase context status code: CLIENT_ERROR Message: no matching artifact paths found

I don't have a clue what is wrong here...

asked a year ago1751 views
2 Answers
0
Accepted Answer

I made some changes in the last line of the buildspec.yml file.

version: 0.2

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
      - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_TAG=${COMMIT_HASH:=latest}
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...          
      - docker build -t $REPOSITORY_URI:latest .
      - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG    
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker image...
      - docker push $REPOSITORY_URI:latest
      - docker push $REPOSITORY_URI:$IMAGE_TAG
      - echo Writing image definitions file...
      - printf '[{"name":"%s","imageUri":"%s"}]' "$IMAGE_REPO_NAME" "$REPOSITORY_URI:$IMAGE_TAG" > imagedefinitions.json
artifacts:
    files: 
      - 'imagedefinitions.json'

And the Build was successful

answered a year ago
0

I thought the syntax of the buildspec.yml was different when I checked the following documentation.
https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-syntax

I think "files" may be a list.
So I thought the last line would be "- imagedefinitions.json".

version: 0.2

phases:

  pre_build:

  commands:

      - echo Logging in to Amazon ECR...

      - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com

      - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME

      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)

      - IMAGE_TAG=${COMMIT_HASH:=latest}

  build:

   commands:

      - echo Build started on `date`

      - echo Building the Docker image...
          
      - docker build -t $REPOSITORY_URI:latest .

      - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG

  post_build:

   commands:

      - echo Build completed on `date`

      - echo Pushing the Docker image...

      - docker push $REPOSITORY_URI:latest

      - docker push $REPOSITORY_URI:$IMAGE_TAG

      - echo Writing image definitions file...

      - printf '[{"name":"%s","imageUri":"%s"}]' "$IMAGE_REPO_NAME" "$REPOSITORY_URI:$IMAGE_TAG" > imagedefinitions.json

artifacts:

  files: 
    - imagedefinitions.json

Another point to check is to make sure that imagedefinitions.json is located in "$CODEBUILD_SRC_DIR". https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html

profile picture
EXPERT
answered a year ago
  • I have tried changing the last line still the same results. Can you give me tutorial or some demo to make sure that imagedefinitions.json is located in "$CODEBUILD_SRC_DIR", Please. I am new to this. Thank you for your taking the initiative and giving time to solve my issue.

  • For example, if you add the command "ls -la $CODEBUILD_SRC_DIR" to the build phase, you should see the directory in the log.

  • Thank you for your help

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions