gpt4 book ai didi

java - 使用 Docker Image 的 MAVEN 项目的 Gitlab CI

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:05:43 27 4
gpt4 key购买 nike

我有一个 java 项目,在那里我进行了测试。现在我有了 .gitlab-ci.yml:

image: maven:latest

stages:
- build

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

每次,当我在我的 repo 中提交时,我都在等待很多时间,它会下载所有依赖项。在 docker 中我们可以使用 volume 选项。问题:我可以下载并在本地编译这个项目以创建 .m2 目录吗,我可以在我的 .gitlab-ci.yml 中使用这个目录吗?如果是的话,你能帮我看看吗,因为我没有在网上找到相关的例子。

我在我的 /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/ 是一个目录,拥有 gitlab-runner 所有者。但这并没有帮助,我们怎么看:

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

最佳答案

采取的步骤:(主机 - 机器 gitlab - 安装了运行器并签署了运行器)

  1. 在主机上克隆你的仓库
  2. 用maven编译
  3. 检查宿主机/root/.m2下是否有缓存数据文件夹
  4. 修复你的 config.toml 添加这一行

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

  1. 然后添加到.gitlab-ci.yml
cache:
paths:
- /root/.m2/

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

.gilatb.yml 应该是这样的

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

关于java - 使用 Docker Image 的 MAVEN 项目的 Gitlab CI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56303459/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com