各位同事们,日安。我在生产中使用gitlab ci。我有很多阶段。(1)构建工件(2)部署到外部服务器(3)使用jfrog cli部署到artifactory
我在缓存maven本地存储库时遇到了问题。我的运行程序在第一步(构建)中下载所有的依赖项,并在最后一步执行同样的操作(部署到工件)。另外,我的跑步者在最后阶段之前从m2文件夹中删除所有数据:
Removing .m2/antlr/
Removing .m2/aopalliance/
Removing .m2/asm/
Removing .m2/avalon-framework/
Removing .m2/backport-util-concurrent/
Removing .m2/ch/
Removing .m2/classworlds/
Removing .m2/com/
Removing .m2/commons-beanutils/
Removing .m2/commons-chain/
Removing .m2/commons-cli/
Removing .m2/commons-codec/
Removing .m2/commons-collections/
Removing .m2/commons-digester/
Removing .m2/commons-io/
Removing .m2/commons-lang/
Removing .m2/commons-logging/
Removing .m2/commons-validator/
Removing .m2/dom4j/
Removing .m2/io/
Removing .m2/javax/
Removing .m2/junit/
Removing .m2/log4j/
Removing .m2/logkit/
Removing .m2/net/
Removing .m2/org/
Removing .m2/oro/
Removing .m2/sslext/
Removing .m2/xml-apis/
Removing .m2/xmlunit/
Removing jfrog
Removing target/我的gitlav-ci yaml(第二步):
stages:
- build
- deploy-artifactory
variables:
MAVEN_OPTS: "-Dmaven.repo.local=${CI_PROJECT_DIR}/.m2"
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
cache:
key: "$CI_JOB_NAME"
paths:
- .m2/
build:
image: maven:latest
stage: build
tags:
- build
script:
- adduser --disabled-password --gecos '' mynonrootuser
- chmod --recursive 777 .
- git version
- su --command='mvn versions:set -DgenerateBackupPoms=false -DnewVersion="$CI_COMMIT_REF_SLUG-SNAPSHOT"' mynonrootuser
- su --command='mvn $MAVEN_CLI_OPTS clean install -B -f ./pom.xml' mynonrootuser
artifacts:
expire_in: 5 mins
paths:
- target/*.jar
only:
- develop
deploy-artifactory-snapshot:
retry: 2
image: maven:latest
stage: deploy-artifactory
tags:
- release
before_script:
- curl -fL https://getcli.jfrog.io | sh
- ./jfrog rt config --url=${ARTIFACTORY_URL} --user=${ARTIFACTORY_USER} --password=${ARTIFACTORY_PASSWORD}
- ./jfrog rt c show
- export M2_HOME=/usr/share/maven
- sed -i 's,MAVEN_REPO_SNAPSHOT_DEPLOYER,'"$MAVEN_REPO_SNAPSHOT_DEPLOYER"',g' configuration.yml
- sed -i 's,MAVEN_REPO_RELEASES_DEPLOYER,'"$MAVEN_REPO_RELEASES_DEPLOYER"',g' configuration.yml
- sed -i 's,MAVEN_REPO_SNAPSHOT_RESOLVER,'"$MAVEN_REPO_SNAPSHOT_RESOLVER"',g' configuration.yml
- sed -i 's,MAVEN_REPO_RELEASES_RESOLVER,'"$MAVEN_REPO_RELEASES_RESOLVER"',g' configuration.yml
script:
- ./jfrog rt mvn "versions:set -DgenerateBackupPoms=false -Dartifactory.publish.artifacts=false -DnewVersion="$CI_COMMIT_REF_SLUG-SNAPSHOT"" configuration.yml --build-name=scdfrestrunner --build-number=$CI_JOB_ID
- ./jfrog rt mvn "clean install" configuration.yml --build-name=scdfrestrunner --build-number=$CI_JOB_ID
- ./jfrog rt bce scdfrestrunner $CI_JOB_ID
- ./jfrog rt bp scdfrestrunner $CI_JOB_ID
only:
- develop发布于 2018-10-27 06:06:20
有几种方法可以处理构建作业/阶段之间的依赖关系。
缓存,这里有指南。
例如,用于m2的缓存部分
# Cache modules in between jobs
cache:
key: ${CI_COMMIT_REF_SLUG} # cache is for per branch
paths:
- ${CI_PROJECT_DIR}/.m2缓存也可以使用类似于米诺 (开源s3,如存储解决方案)之类的东西来执行。与gitlab 这里有指南。集成。但是,由于缓存需要拉链和解压缩,大量的工件可能会导致速度慢(但显然比没有缓存的速度更快)。为了避免这个问题,可以使用坞卷。
码头容积
基本上,我们可以使用开箱即用的对接体,比如安装在主机位置的~/.m2。如果在kubernetes集群中使用,就可以利用库伯纳体积解。您必须自定义构建映像位以支持安装依赖项dir,下面是mvn构建映像的示例。这种方法更好,因为您不能在构建dir之外缓存。
例如码头图像
FROM maven:3.5.4-jdk-8
# m2 dir on docker container
ENV MAVEN_OPTS "-Dmaven.repo.local=/.m2/repository"
ENV MAVEN_CLI_OPTS "-s /usr/local/.m2/settings.xml --batch-mode"
ADD .m2 /usr/local/.m2 # copy settings.xml to build image
# same as the m2 dir specified in MAVEN_OPTS
VOLUME /.m2伪影
如果您只想传递您的构建dir (例如/target ),您可以使用gitlab工件解决方案,指南是可在这里找到。
https://stackoverflow.com/questions/53010163
复制相似问题