AWS CodeBuild + CodePipeline: "No matching artifact paths found"
Asked Answered
S

8

29

I am attempting to get CodePipeline to fetch my code from GitHub and build it with CodeBuild. The first (Source) step works fine. But the second (Build) step fails during the "UPLOAD_ARTIFACTS" part. Here are the relevant log statements:

[Container] 2017/01/12 17:21:31 Assembling file list
[Container] 2017/01/12 17:21:31 Expanding MyApp
[Container] 2017/01/12 17:21:31 Skipping invalid artifact path MyApp
[Container] 2017/01/12 17:21:31 Phase complete: UPLOAD_ARTIFACTS Success: false
[Container] 2017/01/12 17:21:31 Phase context status code: ARTIFACT_ERROR Message: No matching artifact paths found
[Container] 2017/01/12 17:21:31 Runtime error (No matching artifact paths found)

My app has a buildspec.yml in its root folder. It looks like:

version: 0.1

phases:
  build:
    commands:
      - echo `$BUILD_COMMAND`

artifacts:
  discard-paths: yes
  files:
    - MyApp

It would appear that the "MyApp" in my buildspec.yml should be something different, but I'm pouring through all of the AWS docs to no avail (what else is new?). How can I get it to upload the artifact correctly?

Snuffer answered 13/1, 2017 at 2:36 Comment(3)
Have you figured out this I am facing exactly same problem with my nodejs app. If you can please help.Hitormiss
@Hitormiss Yeah, I think I needed to use '*/' as the source, or something like that. Look for the "artifacts" section: docs.aws.amazon.com/codebuild/latest/userguide/…Snuffer
Thank you John for the quick response. I would give it a try. I really appreciate your help.Hitormiss
B
16

The artifacts should refer to files downloaded from your Source action or generated as part of the Build action in CodePipeline. For example, this is from a buildspec.yml I wrote:

artifacts:
  files:
    - appspec.yml
    - target/SampleMavenTomcatApp.war
    - scripts/*

When I see that you used MyApp in your artifacts section, it makes me think you're referring to the OutputArtifacts of the Source action of CodePipeline. Instead, you need to refer to the files it downloads and stores there (i.e. S3) and/or it generates and stores there.

You can find a sample of a CloudFormation template that uses CodePipeline, CodeBuild, CodeDeploy, and CodeCommit here: https://github.com/stelligent/aws-codedeploy-sample-tomcat/blob/master/codebuild-cpl-cd-cc.json The buildspec.yml is in the same forked repo.

Backwoods answered 13/1, 2017 at 16:34 Comment(4)
"you need to refer to the files it downloads and stores there (i.e. S3) and/or it generates and stores there" That makes sense, but how do I know what the names of those values are? I looked in the Source action's S3 bucket, and they appear to be randomly generated names.Snuffer
Sorry, I think my S3 reference confused things. To clarify, in the artifacts/files section of your buildspec, you'll list the files you're using to build from your Source repository (i.e. the files in GitHub - and not the randomly generated names generated from CodePipeline) and any relevant files generated from your build process. It's unclear based on the supplied information which language/platform you're building on.Backwoods
Ah, I now understand. Man, the documentation with these tools is incredibly confounding. Thanks!Snuffer
The phrasing "No matching artifact paths found" is very confusing.Centime
P
7

In my case I received this error because I had changed directory in my build stage (the java project I am building is in a subdirectory) and did not change back to the root. Adding cd ..at the end of the build stage did the trick.

Potentiometer answered 13/2, 2021 at 7:18 Comment(0)
P
3

Buildspec artifacts are information about where CodeBuild can find the build output and how CodeBuild prepares it for uploading to the Amazon S3 output bucket.

For the error "No matching artifact paths found" Couple of things to check:

  1. Artifacts file(s) specified on buildspec.yml file has correct path and file name.

artifacts: files: -'FileNameWithPath'

  1. If you are using .gitignore file, make sure file(s) specified on Artifacts section is not included in .gitignore file.

Hope this helps.

Polaris answered 23/3, 2020 at 13:2 Comment(0)
M
2

There was the same issue as @jd96 wrote. I needed to return to the root directory of the project to export artifact.

build:
 commands:
  - cd tasks/jobs
  - make build
  - cd ../..
post_build:
 commands:
  - printf '[{"name":"%s","imageUri":"%s"}]' $IMAGE_REPO_NAME $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json

artifacts: files: imagedefinitions.json

Mettle answered 29/12, 2022 at 16:46 Comment(0)
G
1

I had the similar issue, and the solution to fix the problem was "packaging directories and files inside the archive with no further root folder creation".

https://docs.aws.amazon.com/codebuild/latest/userguide/sample-war-hw.html

Greenockite answered 24/7, 2018 at 14:24 Comment(0)
H
1

If you're like me and ran into this problem whilst using Codebuild within a CodePipeline arrangement.

You need to use the following

- printf '[{"name":"container-name-here","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > $CODEBUILD_SRC_DIR/imagedefinitions.json
Hugo answered 18/12, 2021 at 3:22 Comment(0)
N
0

Artifacts are the stuff you want from your build process - whether compiled in some way or just files copied straight from the source. So the build server pulls in the code, compiles it as per your instructions, then copies the specified files out to S3.

In my case using Spring Boot + Gradle, the output jar file (when I gradle bootJar this on my own system) is placed in build/libs/demo1-0.0.1-SNAPSHOT.jar, so I set the following in buildspec.yml:

artifacts:
  files:
    - build/libs/*.jar

This one file appears for me in S3, optionally in a zip and/or subfolder depending on the options chosen in the rest of the Artifacts section

Niobium answered 21/3, 2020 at 22:3 Comment(0)
S
0

try using the version 0.2 of the buildspec

here is a typical example for nodejs

version: 0.2
phases:
  pre_build:
    commands:
      - echo Nothing to do in the pre_build phase...
  build:
    commands:
      - npm install
      - npm run build
  post_build:
    commands:
      - echo Build completed on
artifacts:
  files:
    - appspec.yml
    - build/*

Shellbark answered 16/3, 2021 at 11:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.