Jenkins未能在构建前清洁工作空间

ubbxdtey  于 2022-11-01  发布在  Jenkins
关注(0)|答案(3)|浏览(312)

试图设置Jenkins运行在码头集装箱内,也能够运行集装箱那里。
当我运行第一个构建时,所有的工作都很好,但当我运行第二个构建时,我遇到了以下问题。
有人知道问题出在哪里吗?
这是pipeline的日志

Started by user Vit @ Jarmill
Replayed #4
Connecting to https://api.github.com using admin/******(GitHub Access      Token)
Obtained Jenkinsfile from 382099092e83938b97a09ec5c8d627dd7456411d
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/iamwtk_site_master-  E6LR65PLWYZWNGUMZKPLCLOJ337SJ4G4F2WDI7TROT63NGV36NEQ
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)

[Pipeline] checkout

 > git rev-parse --is-inside-work-tree # timeout=10

Fetching changes from the remote Git repository

> git config remote.origin.url https://github.com/iamwtk/iamwtk_site.git # timeout=10

Cleaning workspace

> git rev-parse --verify HEAD # timeout=10

Resetting working tree

> git reset --hard # timeout=10

> git clean -fdx # timeout=10

ERROR: Error fetching remote repo 'origin'

hudson.plugins.git.GitException: Failed to fetch from https://github.com/iamwtk/iamwtk_site.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:888)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1155)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1186)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:113)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:85)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:75)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate(ACL.java:290)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Caused by: hudson.plugins.git.GitException: Command "git clean -fdx" returned status code 1:

stdout: Removing front_end_server@tmp/

stderr: warning: failed to remove front_end_server/dist/server.js

warning: failed to remove front_end_server/dist/client/views/index.ejs

// and many more ....

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2002)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1970)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1966)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1597)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1609)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.clean(CliGitAPIImpl.java:787)
at hudson.plugins.git.GitAPI.clean(GitAPI.java:311)
at hudson.plugins.git.extensions.impl.CleanBeforeCheckout.decorateFetchCommand(CleanBeforeCheckout.java:30)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:884)
... 13 more

[Pipeline] }

[Pipeline] // stage

[Pipeline] }

[Pipeline] // node

[Pipeline] End of Pipeline

GitHub has been notified of this commit’s build result

ERROR: Error fetching remote repo 'origin'

Finished: FAILURE

我使用以下设置启动了容器:

docker volume create --name data_jenkins
docker run --name jenkins -d -v data_jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts

我已经在容器内安装了docker,它的守护进程通过卷链接到主机守护进程。我将jenkins用户设置为docker组,以便能够在没有sudo的情况下运行docker命令。
我很确定这一定是权限问题,只是我真的找不到位置。已经花了一整天的时间在这上面,希望有人能给我指个方向。

k7fdbhmy

k7fdbhmy1#

问题出在储存组建的工作区目录中的权限。
更改了权限,允许jenkins用户使用rwx,问题解决。

ippsafx7

ippsafx72#

我只是这样做:

stage('delete files from workspace') {
  steps {
    sh 'ls -l'
    sh 'sudo rm -rf ./*'
  }
}

作为scm结账前的步骤之一,它的工作就像一个魅力。

zsbz8rwp

zsbz8rwp3#

要解决此问题,您需要清理工作区
1.复制工作空间路径(可以从作业控制台输出中复制工作空间的路径)例如:- /opt/jenkins/workspace/job_name
2.打开Jenkins示例的shell或ssh(如果是VM或EC2示例)

  1. rm -rf /opt/jenkins/工作区/作业名称或(如果出现获取权限被拒绝错误)sudo rm -rf /opt/jenkins/工作区/作业名称

相关问题