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

I experimented without any success, I run Gitlab hosted on Linux and try to understand the CI functionality.

According to the Gitlab documentation, you need to create a .gitlab-ci.yml , an implementation of Gitlab Travis-CI. Now you can do a lot from the .gitlab-ci.yml with .gitlab-ci.yml , but most of the documentation is related to Ruby and other languages. Nothing is said about how to create Java Maven projects.

How can I create a simple Java application? Can I use a common runner, or should I use a specific runner, in this case, which or which implementation of the runner should I choose: ssh, docker or shell? Then, what should I put in a .gitlab-ci.yml , at least to create a project using Maven?

+44
java spring maven gitlab-ci gitlab-omnibus
Oct 30 '15 at 7:07
source share
5 answers

Register your Docker runner and use one of the official Mock Docker images , for example maven:3-jdk7 in the .gitlab-ci.yml :

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

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

As far as I understand, it doesn't matter if the runner is general or specific.

+40
Jan 08 '16 at 15:41
source share

The documentation describes the YAML syntax used to manage assemblies:

So why don't you try starting with the following ?:

 job1: script: "mvn package" 

Presumably this will only work if Maven is already installed, so you'll need a runner that supports this.

I have not used GitLab, but the documentation suggests that you additionally configure it to use the official Maven Docker image to complete the build. It looks very interesting, but I would agree that there is no Java example in the documentation.

+4
Oct. 30 '15 at 8:56
source share

I would like to add some information here guys. First, make some confusion about the general and specific runner.

Shared runner: As his name sounds, the shared participants are instances of the build process thread that can be used to complete the tasks of each individual project in the installed gitlab instance with the Allowed shared runners option enabled. You will need administrative rights to do this. According to current gitlab documentation, only admin use can define a common runner.

specific runner This type of runner carries out tasks of only one project.

In addition, these are some important points to consider when choosing a runner for your projects.

  • Common contributors are useful for assignments that have similar requirements between several projects. Instead of having multiple runners idling for many projects, you may have one or a small number of runners who handle several projects. This simplifies maintenance and updating runners for a common set of projects.
  • Special runners are useful for tasks that have special requirements or for projects with special demand. If the task has certain requirements, you can configure a specific runner to take this into account, without requiring it for all participants. For example, if you want to deploy a specific project, you can configure a specific runner to get the correct credentials for this.

Now, in order to choose the right artist for the project, it is very important that we have a bird view of all available artists for gitlab runner. Gitlab simplified this work by providing good documentation here , explaining what different options you have for different artists.

If you want to know more about runners and different artists, I would advise you to start with this article, Gitlab Runner

+3
Jan 20 '17 at 7:34 on
source share

I use this command, but overall java / maven assembly documentation seems pretty rare

 maven-package: script: "mvn install -B" 
+2
Apr 15 '16 at 8:50
source share

I spent a lot of time trying to set up our Java projects on Gitlab CI. I got the job with some success. As mentioned above, the most direct solution is to use an image from the official repo: https://hub.docker.com/_/maven

However, we do have a corporate proxy server that forced my builds to receive timeout requests when selecting project dependencies. I tried many solutions and finally came across this post: https://gitlab.com/gitlab-org/gitlab-ce/issues/15167 .

The premise itself is to configure maven to cache downloaded dependencies in a local repo, which can be accessed between assemblies. The idea is that you can write a local maven configuration file in .gitlab-ci.yml to configure the cache directory and your proxy.

 before_script: -echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>/cache/.m2</localRepository> <proxies> <proxy> <active>true</active> <protocol>'$PROXY_PROTOCOL'</protocol> <host>'$PROXY_HOST'</host> <port>'$PROXY_PORT'</port> </proxy> </proxies> </settings>' > $HOME/.m2/settings.xml build_debug1: stage: build script: "echo $PROXY_HOST" build_debug2: stage: build script: "cat $HOME/.m2/settings.xml" build_maven: stage: build script: "mvn $MAVEN_CLI_OPTS package" artifacts: paths: - target/*.jar deploy_debug1: stage: package script: "ls target/" 

Please note that assembly debugging tasks are intended only to verify that the proxy server parameters are entered correctly. You can set proxy server environment variables as secrets using Gitlab by going to Project → Settings → CI / CD Pipelines → Secret Variables.

The final deploy_debug job is to see what was created in your target directory.

0
Jul 06 '17 at 14:00
source share



All Articles