为什么我的 Spring Boot 构建无法使用 OpenShift 运行程序在我的 GitLab CICD 管道中创建 .m2 存储库?

问题描述 投票:0回答:2

我是 CICD 新手,尝试在 GitLab CICD 管道上简单构建 Spring Boot Java 应用程序。我正在关注本教程(以及其他教程):about.gitlab.com/blog/2016/12/14/continuous-delivery-of-a-spring-boot-application-with-gitlab-ci-and-kubernetes/

对于我的 .gitlab-ci.yml 文件,我有以下内容:

image: docker:latest

stages:
  - build

maven-build:
  image: maven:3-jdk-8
  stage: build
  script: "mvn clean package -B"
  artifacts:
      paths:
        - target/*.jar

但是,由于某种原因,当我运行管道时,我不断收到以下错误:

$ mvn clean package -B
[ERROR] Could not create local repository at /.m2/repository -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LocalRepositoryNotAccessibleException
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: command terminated with exit code 1

尽管遵循了教程(并找到了其他类似的教程),我仍然收到此错误。我尝试过以下方法:

  • 验证运行器是否正常工作并且能够处理管道。
  • 验证 Spring Boot 应用程序在我的设备上成功运行 本地机器。
  • 尝试使用不同版本的命令(例如 “mvc 包-B”)。
  • 在我的本地成功编译了应用程序 使用maven命令行的机器。

我的代码似乎一切正常,那么为什么我会收到此错误?值得注意的是,我的 GitLab 运行器托管在 OpenShift 上。在 GitLab 或 OpenShift 上是否存在我忽略的某种权限设置?

spring-boot gitlab gitlab-ci openshift gitlab-ci-runner
2个回答
0
投票

由于权限问题,OpenShift 可能不允许您的 GitLab pod 运行。默认情况下,OpenShift 限制 pod 在有限权限下运行。您可以通过运行来检查 pod 的日志

kubectl logs <runner-pod-name>

进一步调试问题。


0
投票

我有一个用于 Spring Boot 的 Gitlab CICD 脚本,用于使用 maven 构建 Spring Boot,然后将其作为容器部署到 docker。希望这个脚本能有所帮助。

image: gitlab/dind
services:
  - docker:find
variables:
  MAVEN_OPTS: -Dmaven.repo.local=.m2/repository
  DOCKER_DRIVER: overlay2
stages:
  - build-test
  - deploy
cache:
  paths:
    - .m2/repository/
maven-build:
  image: maven:3.8.5-openjdk-17
  stage: build-test
  script: mvn clean install package
  artifacts:
    paths:
      - target/*.jar
docker-build:
  stage: deploy
  cache: {}
  script:
    - docker build -t imageName:latest .
    - docker run -d --name yourconatainername -p 8080:8080 imageName:latest
  only:
    - dev
  retry: 1

如果您对该脚本有具体问题,请告诉我。谢谢你

© www.soinside.com 2019 - 2024. All rights reserved.