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
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.
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:
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 , 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 S3.
Hope it’s clear with the images.