0

In Jenkins in K8S pod I'm using checkout in my scripted pipeline (The job is running in root permission) -

checkout([$class           : 'GitSCM', branches: [[name: branch]], doGenerateSubmoduleConfigurations: false,
                      extensions       : [[$class: 'CheckoutOption', timeout: 120]], submoduleCfg: [],
                      userRemoteConfigs: [[credentialsId: gitCredentials, url: url]],
                      clean: false])

But I'm getting this error -

ERROR: Failed to clean the workspace
15:10:05  jenkins.util.io.CompositeIOException: Unable to delete '/home/jenkins/agent/workspace/

After verifying the filesystem permissions, I've figured out I'm using root permissions in the entire job (If I do sh 'whoami' I see root), but I think the checkout itself is using 'Jenkins' permissions and therefore it cannot remove files that has root permissions

Can I -

  1. Use different user permissions? like Jenkins for example but just for the checkout? I don't want to have Jenkins permissions to the entire job.

  2. Can I skip cleanup? If the issue with the cleanup, I can avoid it, how can I do checkout of a branch without cleanup?

EilonA
  • 361
  • 5
  • 17
  • In my case there is a property in pipeline definition, this is the help: If checked, the workspace will not be deleted and re-created at the start of each build, making the build faster, but this causes the artifacts from the previous build to remain when a new build starts. You should avoid using root user to do your job. I'm using docker compose for my jcasc jenkins setup, it runs as jenkins user, I do not need to have root privilege, why you need it? – Lety Jun 07 '23 at 12:51
  • because we are using many root related tasks.. Like docker build for example.. I cannot run docker build as non root what check did you do to avoid cleanup workspace? – EilonA Jun 07 '23 at 13:01
  • 1. Why do you use the `[$class: 'GitSCM', ...]` syntax rather than the simpler [`scmGit(...)`](https://www.jenkins.io/doc/pipeline/steps/params/scmgit/)? And there's no `clean` argument in [`scmGit`](https://www.jenkins.io/doc/pipeline/steps/params/scmgit/) any longer. There's just [`GitSCMBackwardCompatibility.getClean()`](https://javadoc.jenkins.io/plugin/git/hudson/plugins/git/GitSCM.html#methods.inherited.from.class.hudson.plugins.git.GitSCMBackwardCompatibility) in the latest API. ...cont'd... – Gerold Broser Jun 07 '23 at 13:25
  • 2. Are you sure that the error occurs at `checkout` and not at [`cleanWs`](https://www.jenkins.io/doc/pipeline/steps/ws-cleanup/#cleanws-delete-workspace-when-build-is-done)? – Gerold Broser Jun 07 '23 at 13:25
  • In my case jenkins can run docker command because I add jenkins user to docker group in jenkins dockerfile. I found this https://stackoverflow.com/questions/17637528/how-to-have-jenkins-not-clean-a-git-workspace that could help – Lety Jun 08 '23 at 06:26
  • Yes, it occures at checkout – EilonA Jun 11 '23 at 06:58
  • Still not idea why it happens at the place in code – EilonA Jun 11 '23 at 06:58

0 Answers0