Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

570
Views
Gitlab CI for MAVEN project with Docker Image

I have project on java, where i have my tests. Now i have .gitlab-ci.yml:

image: maven:latest

stages:
  - build

build:
  stage: build
  script:
    - mvn test-compile compile
  tags:
    - mytag
  only:
    refs:
      - dev

Each time, when i am making commit in my repo, i am waiting a lot of time, when it will download all depencies. In docker we can use volume option. The question: Can i download and compile locally this project for creating of .m2 directory, and can i use this directory in my .gitlab-ci.yml. If yes, can you help me how, because i have not found in internet examples according to it.

I made changes in my /etc/gitlab-runner/config.toml:

  [runners.docker]
    tls_verify = false
    image = "maven:latest"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache","/M2/.m2:/root/.m2"]
    shm_size = 0

/M2/ is a dir, with gitlab-runner owner. But it does not help, how we can see:

Downloaded from central: https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-parent/1.3/hamcrest-parent-1.3.pom (2.0 kB at 20 kB/s)
Downloading from atlas: https://dl.bintray.com/qameta/maven/org/seleniumhq/selenium/selenium-java/3.8.1/selenium-java-3.8.1.pom
Downloading from nio: http://clojars.org/repo/org/seleniumhq/selenium/selenium-java/3.8.1/selenium-java-3.8.1.pom
Downloading from central: https://repo.maven.apache.org/maven2/org/seleniumhq/selenium/selenium-java/3.8.1/selenium-java-3.8.1.pom
Progress (1): 2.2/5.9 kB
Progress (1): 5.0/5.9 kB
Progress (1): 5.9 kB    
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

steps to take: (host machine - the machine gitlab - runner installd on and the runner signed)

  1. clone your repository on the host machine
  2. compile it with maven
  3. check that there is cached data folder under /root/.m2 on the host machine
  4. fix your config.toml add this line

volumes = ["/cache","~/.m2:/root/.m2"]

  1. then add to .gitlab-ci.yml
cache:
  paths:
    - /root/.m2/

variables: MAVEN_OPTS: "-Dmaven.repo.local=.m2"

the .gilatb.yml should look like this

https://stackoverflow.com/a/40024602/4267015

over 4 years ago · Santiago Trujillo Report

0

  • I build a "base docker image". Copy pom.xml to docker image and then run maven verify that image. This is dockerFile:
FROM maven:3.6.1-jdk-8-alpine
COPY pom.xml .
RUN mvn verify clean --fail-never
  • Open Terminal, then go to the project directory and run docker build:

docker build -t xxx/projectName:base .

  • Now "base docker image" has cached data.

  • And then You can use "base docker image" in gitlab-ci.yml:

image: xxx/projectName:base

stages:
  - build

build:
  stage: build
  script:
    - mvn test-compile compile
  tags:
    - mytag
  only:
    refs:
      - dev
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!