4

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    
Piduna
  • 609
  • 12
  • 28

2 Answers2

2

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

Sergey Benner
  • 4,421
  • 2
  • 22
  • 29
Naor Tedgi
  • 5,204
  • 3
  • 21
  • 48
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
The Sun
  • 503
  • 1
  • 3
  • 13