【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),所以进入容器修改一次之后就会一直生效。

相关推荐
high20112 小时前
【Git】-- 版本说明
git
kaixin_learn_qt_ing2 小时前
git clone
git
sin22012 小时前
git stash
git
喝鸡汤2 小时前
一起学Git【第二节:创建版本库】
git
慢慢成长的码农2 小时前
git 同步分支操作
git
sin22012 小时前
git推送本地仓库到远程(Gitee)
git·gitee
woshiabc1113 小时前
windows安装Elasticsearch及增删改查操作
大数据·elasticsearch·搜索引擎
丁总学Java4 小时前
git branch -r(--remotes )显示你本地仓库知道的所有 远程分支 的列表
git
coder_pig4 小时前
📝小记:Ubuntu 部署 Jenkins 打包 Flutter APK
flutter·ubuntu·jenkins
arnold666 小时前
探索 ElasticSearch:性能优化之道
大数据·elasticsearch·性能优化