【Jenkins】解决使用容器化部署的Jenkins Agent节点时出现的git检查报错

报错日志:

bash 复制代码
Running on agent-0.230 in /home/jenkins/workspace/pipeline-test
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout from GitLab)
[Pipeline] git
ERROR: Checkout failed
Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from 192.168.0.230/192.168.0.230:45106
		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1826)
		at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
		at hudson.remoting.Channel.call(Channel.java:1042)
		at hudson.FilePath.act(FilePath.java:1229)
		at hudson.FilePath.act(FilePath.java:1218)
		at hudson.FilePath.mkdirs(FilePath.java:1409)
		at PluginClassLoader for git//hudson.plugins.git.GitSCM.createClient(GitSCM.java:843)
		at PluginClassLoader for git//hudson.plugins.git.GitSCM._checkout(GitSCM.java:1299)
		at PluginClassLoader for git//hudson.plugins.git.GitSCM.checkout(GitSCM.java:1277)
		at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:136)
		at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:101)
		at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:88)
		at PluginClassLoader for workflow-step-api//org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
		at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
		at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
		at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
		at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.nio.file.AccessDeniedException: /home/jenkins/workspace/pipeline-test
	at java.base/sun.nio.fs.UnixException.translateToIOException(Unknown Source)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)
	at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(Unknown Source)
	at java.base/java.nio.file.Files.createDirectory(Unknown Source)
	at java.base/java.nio.file.Files.createAndCheckIsDirectory(Unknown Source)
	at java.base/java.nio.file.Files.createDirectories(Unknown Source)
	at Jenkins v2.462.2//hudson.FilePath.mkdirs(FilePath.java:3753)
	at Jenkins v2.462.2//hudson.FilePath$Mkdirs.invoke(FilePath.java:1419)
	at Jenkins v2.462.2//hudson.FilePath$Mkdirs.invoke(FilePath.java:1414)
	at Jenkins v2.462.2//hudson.FilePath$FileCallableWrapper.call(FilePath.java:3615)
	at hudson.remoting.UserRequest.perform(UserRequest.java:225)
	at hudson.remoting.UserRequest.perform(UserRequest.java:50)
	at hudson.remoting.Request$2.run(Request.java:391)
	at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:81)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:140)
	at java.base/java.lang.Thread.run(Unknown Source)
ERROR: Maximum checkout retry attempts reached, aborting

解决方案:

根据日志内容可以看出是在执行mkdir创建目录时没有权限导致的。

进入容器检查/jenkins/workspace的权限和所有者时确实发现情况不太对,更改所有者和组为jenkins:jenkins之后问题解决.

进入容器指令:

bash 复制代码
docker exec -u root -it jenkins-agent /bin/bash

更改组和所有者指令:

bash 复制代码
chown jenkins:jenkins workspace/

PS: 我的workspace目录做了持久化处理(挂载了docker volume),所以进入容器修改一次之后就会一直生效。

相关推荐
武子康7 小时前
大数据-169 Elasticsearch 入门到可用:索引/文档 CRUD 与搜索最小示例
大数据·后端·elasticsearch
xuanzdhc7 小时前
Gitgit
java·linux·运维·服务器·c++·git
一点事18 小时前
git:通过令牌方式访问远程仓库
git
或非与20 小时前
windows版本git代码自动更新
git
这是个栗子20 小时前
git报错:‘git‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
git
小生不才yz20 小时前
(二)日常工作流 - git rm 命令的使用
git
inferno20 小时前
TortoiseGit下载与安装
git
取名真是20 小时前
Git 到底是干啥的?零基础小白听完都懂了并且轻松驾驭它
git
star_11121 天前
Jenkins部署后端springboot微服务项目
spring boot·微服务·jenkins
AA陈超1 天前
Git常用命令大全及使用指南
笔记·git·学习