jenkins 部署错误 cannot open .git/FETCH_HEAD: Permission denied 解决办法

博主在 jenkins build 时因执行两条命令导致出错,这是权限问题。网上暴力解决办法是将.git 目录设为 777 权限,博主认为将.git 的用户和用户组设为 jenkins 更为温和。

我在 jenkins build 的时候执行了两条命令导致 build 出错

cd /docker/www.xiaobinqt.cn/ && 
git pull origin master

在这里插入图片描述
这是一个权限问题,网上有一个很暴力的解决办法是将 .git 目录设为 777 权限,当然这是一个解决办法,但是不是最好个人觉得.
个人觉得将 .git 的用户和用户组设为 jenkins 似乎更温和些.

chown -R jenkins:jenkins .git

在这里插入图片描述
在这里插入图片描述

Started by user codemylife Running as SYSTEM Building in workspace /var/jenkins_home/workspace/weblog-springboot The recommended git tool is: NONE using credential 87b14820-3dea-45ea-bc41-8d8a63927482 > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/weblog-springboot/.git # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://gitee.com/code-my-life/weblog.git # timeout=10 ERROR: Error fetching remote repo 'origin' hudson.plugins.git.GitException: Failed to fetch from https://gitee.com/code-my-life/weblog.git at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999) at PluginClassLoader for git//hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1240) at PluginClassLoader for git//hudson.plugins.git.GitSCM._checkout(GitSCM.java:1311) at PluginClassLoader for git//hudson.plugins.git.GitSCM.checkout(GitSCM.java:1278) at hudson.scm.SCM.checkout(SCM.java:540) at hudson.model.AbstractProject.checkout(AbstractProject.java:1250) at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:649) at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:522) at hudson.model.Run.execute(Run.java:1860) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44) at hudson.model.ResourceController.execute(ResourceController.java:101) at hudson.model.Executor.run(Executor.java:454) Caused by: hudson.plugins.git.GitException: Command "git config remote.origin.url https://gitee.com/code-my-life/weblog.git" returned status code 128: stdout: stderr: fatal: not in a git directory at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2847) at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2772) at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2767) at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2060) at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2072) at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.setRemoteUrl(CliGitAPIImpl.java:1671) at PluginClassLoader for git-client//hudson.plugins.git.GitAPI.setRemoteUrl(GitAPI.java:182) at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:987) ... 12 more ERROR: Error fetching remote repo 'origin' Finished: FAILURE
08-25
Started by user Fly Running as SYSTEM Building in workspace C:\ProgramData\Jenkins\.jenkins\workspace\ZrLog项目 The recommended git tool is: NONE using credential ca305872-f337-4105-ba2c-b97a40bbfb4e > git.exe rev-parse --resolve-git-dir C:\ProgramData\Jenkins\.jenkins\workspace\ZrLog项目\.git # timeout=10 Fetching changes from the remote Git repository > git.exe config remote.origin.url git@gitee.com:hu-jia-san-shao/zr-log.git # timeout=10 Fetching upstream changes from git@gitee.com:hu-jia-san-shao/zr-log.git > git.exe --version # timeout=10 > git --version # 'git version 2.48.1.windows.1' using GIT_SSH to set credentials Verifying host key using known hosts file You're using 'Known hosts file' strategy to verify ssh host keys, but your known_hosts file does not exist, please go to 'Manage Jenkins' -> 'Security' -> 'Git Host Key Verification Configuration' and configure host key verification. > git.exe fetch --tags --force --progress -- git@gitee.com:hu-jia-san-shao/zr-log.git +refs/heads/*:refs/remotes/origin/* # timeout=10 ERROR: Error fetching remote repo 'origin' hudson.plugins.git.GitException: Failed to fetch from git@gitee.com:hu-jia-san-shao/zr-log.git at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999) at PluginClassLoader for git//hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1240) at PluginClassLoader for git//hudson.plugins.git.GitSCM._checkout(GitSCM.java:1311) at PluginClassLoader for git//hudson.plugins.git.GitSCM.checkout(GitSCM.java:1278) at hudson.scm.SCM.checkout(SCM.java:540) at hudson.model.AbstractProject.checkout(AbstractProject.java:1250) at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:649) at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:522) at hudson.model.Run.execute(Run.java:1833) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44) at hud
03-12
Started by user huzng Running as SYSTEM Building in workspace /var/jenkins_home/workspace/dcloud-short-link-account The recommended git tool is: NONE using credential 1f0bf418-ebd2-4381-9ec9-090e12e122ea > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/dcloud-short-link-account/.git # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://gitee.com/huzng0816/dcloud-short-link.git # timeout=10 Fetching upstream changes from https://gitee.com/huzng0816/dcloud-short-link.git > git --version # timeout=10 > git --version # 'git version 2.39.5' using GIT_ASKPASS to set credentials gitee凭证 > git fetch --tags --force --progress -- https://gitee.com/huzng0816/dcloud-short-link.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10 Checking out Revision 06a132ebd53b4aedcf207fa67ef4431ebb9dda4e (refs/remotes/origin/master) > git config core.sparsecheckout # timeout=10 > git checkout -f 06a132ebd53b4aedcf207fa67ef4431ebb9dda4e # timeout=10 Commit message: "打包配置" First time build. Skipping changelog. [dcloud-short-link-account] $ /bin/sh -xe /tmp/jenkins3295438651166041262.sh + echo 登录阿里云镜像 登录阿里云镜像 + docker login login --username=huzng crpi-cgofe8pfpyt8kzhw.cn-shenzhen.personal.cr.aliyuncs.com --password=Hzh728675. /tmp/jenkins3295438651166041262.sh: 3: docker: Permission denied Build step 'Execute shell' marked build as failure Finished: FAILURE
09-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值