Using ant with CodeBuild - build.xml does not exist and other questions for

0

I am trying to switch over to using CodeBuild to build my code so I can then easily push it to my EC2 instances instead of manually building and copying.

I can manually run ant on my station and all will build as it should.
I am now trying to use the AWS CodeBuild console to try this.
I zipped up my source code files and put it in an S3 bucket and put its location in the source fields of AWS CodeBuild. I have the build.xml in this same bucket and I also put the build.xml in the base of the codes zip file. In the build commands I put "ant".

I assume that the build.xml needs to go somewhere else?
Do I need more then just "ant" in the build commands? That is all I use when i manually build the project.

From what I have read i should be able to zip up my code , put it in the S3 location and CodeBuild will extract it and build it correct?

Also, under "Environment: How to Build" - what is the "Output files" section for? It's not for the artifacts that are built correct?

Any other tips or tricks? I am very new to all of this so any help is appreciated! I just learned about ant this week. This is building a rather large project with many classes being built - Will this cause an issue? Like I stated earlier - I do have it building file if I run it manually on my system.

Here is the error I get when I build through Code Build:
[Container] 2019/03/21 15:32:27 Entering phase BUILD
[Container] 2019/03/21 15:32:27 Running command ant
Buildfile: build.xml does not exist!
Build failed

ernievd
asked 5 years ago549 views
6 Answers
0
Accepted Answer

I have it working! I will post my findings for others going that might be struggling -

So I figured out that the "Outputs" means what are all the files and/or directories that you want to go into your final artifact after all is built.

I have two directories that I want in the final jar artifact. One is WebContent and the other is build. They both have multiple sub-directories. I put "WebContent/,build/" in the output files field. It gave me a jar artifact but when I open the jar it did not have any sub-directories. In order to get it to include all sub-directories I had to make the output files field with "WebContent//,build//". All sub-directories are now in the zip and it appears as if the build was successful.
Hopefully this can help others out.
Now on to creating a script for this and also getting this to work from GitLab.

Edited by: ernievd on Mar 22, 2019 6:32 AM

ernievd
answered 5 years ago
0

Hi ernievd,

This could be a misconfiguration of the build source. Can you PM me a build ARN for a failing build? I'd be happy to look into this for you.

answered 5 years ago
0

Thanks Joseph! Any help is appreciated!!

I figured out my issue - I zipped the build files from the folder level and not the root level. I re-zipped and it can now see the build.xml.

The next issue I have is that in my original build.xml it was getting the tomcat library files from my local computer - <fileset dir="/usr/local/tomcat/lib">

To overcome this I manually copied the files in that lib directory, put them in a new location in the zip file and then updated the build.xml to look at the new location. Is there any way to tell CodeBuild to look for files on the local computer or do i always have to have these tomcat files in the zipped file?

I built again with these changes and it looks like I am close! It failed for the following -

[Container] 2019/03/21 20:57:13 Phase complete: BUILD Success: true
[Container] 2019/03/21 20:57:13 Phase context status code: Message:
[Container] 2019/03/21 20:57:13 Entering phase POST_BUILD
[Container] 2019/03/21 20:57:13 Phase complete: POST_BUILD Success: true
[Container] 2019/03/21 20:57:13 Phase context status code: Message:
[Container] 2019/03/21 20:57:13 Expanding base directory path: .
[Container] 2019/03/21 20:57:13 Assembling file list
[Container] 2019/03/21 20:57:13 Expanding .
[Container] 2019/03/21 20:57:13 Expanding artifact file paths for base directory .
[Container] 2019/03/21 20:57:13 Assembling file list
[Container] 2019/03/21 20:57:13 Expanding myapp.jar
[Container] 2019/03/21 20:57:13 Skipping invalid artifact path myapp.jar
[Container] 2019/03/21 20:57:13 Phase complete: UPLOAD_ARTIFACTS Success: false
[Container] 2019/03/21 20:57:13 Phase context status code: CLIENT_ERROR Message: no matching artifact paths found

The arn is -
arn:aws:codebuild:us-east-1:499000881936:build/TroveBuild:db1f5206-228d-46aa-9450-82407546ad17

ernievd
answered 5 years ago
0

Hi ernievd,

You could build a customer docker image that has these files in the same area as you desktop. If you don't want to do this then putting them in your zip is a great solution.

Looks like your running into an issue where we can't find the artifact file that you specified named myapp.jar. I would do an ls and see if that file is in your base directory or if its somewhere else like bin/myapp.jar .
John

answered 5 years ago
0

Isn't bin/myapp.jar what the build is creating?

I am very confused as to what the Artifact/name should be - isn't this what is being created from the build? It is asking for an ARN - how can there be an ARN for it when it is not created?

Also very confused as to what the Environment/Output files is? It is required but I have no idea what should go in this field? It states that output files can not be empty. Does this mean it wants all the class files that are being built? If so then this build is creating over 30 class files in multiple locations - that is a ton to list.

Thanks
Ernie

ernievd
answered 5 years ago
0

Hi ernievd,

You'll need the artifacts' files: section of your buildspec.yml to include the path to your jar. This is how CodeBuild determines which files should be considered artifacts. From your logs, it looks like the path may not be correct.

The Project configuration and artifact path/namespace/name tells CodeBuild where you want these artifacts to go after the build, and how you want them (re)named and packaged.

answered 5 years ago

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