0

I feel as though I've trawled the entire internet and SO previous questions and tested every combination and permutation to try and get this working, but nothing at all I try works. I cannot seem to find a reliable guide to follow for this and/or decent logging.

A local Maven build of the .war file and the manual upload of the .war file to Elastic Beanstalk works absolutely fine.

But I really don't want to be having to do this.

Many of the options I've tried from the guides, end up with the CodeBuild process working and apparently saving the output to S3 - but when I click the link, to the S3 object, it's not there.

Here's the latest buildspec.yml file for what it's worth.

version: 0.2

phases:
  install:
    runtime-versions:
      java: corretto11

  build:
    commands:
      - mvn clean
      - mvn install
      
post_build:
    commands:
      - mv target/MyApp-1.0.war ROOT.war
      
artifacts:
  files:
      - ROOT.war

I'm not sure the mv command is needed as when I check the CodeBuild logs, I can see this;

[INFO] Building war: /codebuild/output/src1021125740/src/target/MyApp-1.0.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Any ideas on next steps to try? If I can at least get the war file generating and accessible either on S3 or CodeArtifact or passing it directly to the next step for CodeDeploy then I should hopefully be able to figure out the rest.

2 Answers 2

0

The artifacts section in buildspec.yml is essential as it directs CodeBuild on which files to upload to S3 after the build process completes. To ensure the files are uploaded to the root path in S3, you can include discard-paths: yes in the configuration:

artifacts:
  files:
    - ROOT.war
  discard-paths: yes

Additionally, it’s important to define an output artifact for your build step, such as BuildArtifact, to track the generated files. If you’re using a standalone CodeBuild project, make sure it’s configured with the correct S3 bucket name and folder path, and that the required permissions are granted to the build role. If CodeBuild is part of a CodePipeline, ensure these configurations are applied to the pipeline’s build stage with the required permission to the codepipeline role. Once set up, you’ll find the artifacts in the specified S3 location.

Once you configure it as an outputArtifact in the build step enter image description here, you can configure it as an inputArtifact in the next stage (which will be the Deploy stage) in the deploy step, and you'll be able to access it also in S3enter image description here.

Hope it's clear with the images.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Fedi Bounouh - As you're from AWS - See my answer about at the root cause of this was. Might want to upgrade the UI to make this more obvious. It's on Step 4 of 4 and states "The CodeBuild project build spec maven configuration" - Reading this now I know what solved this issue, this wording is ambigious - I assumed this was related to the buildspec.yml file in the codebase. Anyhow, thanks for the help and quick response. That got me where I needed.
0

Solved. When the CodeBuild step was created, from the AWS Template for Maven, it defaults to a CodeBuild Buildspec.yml file, rather than the one in the codebase - rather annoyingly - and it doesn't tell you it's doing that.

When I moved the buildspc.yml file contents into the AWS Console Buildspec section within CodeBuild then things started to work again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.