同学们好。我在生产中使用 gitlab ci。我有很多阶段。1)构建工件 2)部署到外部服务器 3)使用 jfrog cli 部署到工件
我在缓存 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