Jenkins无法在构建之前清理工作空间

时间:2018-07-14 16:40:58

标签: git jenkins jenkins-pipeline

尝试设置在Docker容器中运行的Jenkins,并且还可以在其中运行容器。

当我第一次运行时,所有功能都很好,但是当我运行第二个时,我遇到了以下问题。

有人知道这可能是什么问题吗?

这是管道中的日志

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命令。

我非常确定这一定是权限问题,我只是真的找不到位置。已经花了整整一整天的时间,希望有人能为我指明正确的方向。

2 个答案:

答案 0 :(得分:0)

问题是在存储构建的工作空间目录中具有权限。

更改了权限,以允许jenkins用户rwx并解决了问题。

答案 1 :(得分:0)

我只是这样做:

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

作为scm结帐之前的步骤之一,它像一种魅力。

相关问题