Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Gitlab CI to build a Java Maven project?

I have been experimenting with no success whatsoever, I am running a Gitlab hosted on Linux, and trying to get my head around the CI functionality.

According to the Gitlab documentation you only need to create a .gitlab-ci.yml file, the Gitlab implementation of Travis-CI. Now from the looks of it you can accomplish a lot with the .gitlab-ci.yml, but a lot of the documentation is referencing Ruby and other languages. Nothing is said about how to build Java Maven projects.

How can I build a simple application in Java? Can I use the shared runner, or should I be using a specific runner, in that case what or which runner implementation should I choose: ssh, docker, or shell? Then, what should I put in the .gitlab-ci.yml file at least to build the project with Maven?

like image 790
MRK187 Avatar asked Oct 30 '15 07:10

MRK187


People also ask

What can you do with GitLab CI?

GitLab CI/CD is the part of GitLab that you use for all of the continuous methods (Continuous Integration, Delivery, and Deployment). With GitLab CI/CD, you can test, build, and publish your software with no third-party application or integration needed.


1 Answers

Register a Docker runner and use one of the official Maven Docker images, e.g., maven:3-jdk-11 in your .gitlab-ci.yml file:

image: maven:3-jdk-11  build:   script: "mvn install -B" 

Note the -B flag, which is recommended for non-interactive use.

As far as I understand, it does not matter whether the runner is shared or specific.

like image 78
rolve Avatar answered Sep 22 '22 00:09

rolve