Permission denied while running shell bash command with lxc-container in jenkins

73 Views Asked by At

When running this block in Jenkinsfile:

String runTest = """
                #!/bin/bash
                if [ ${EXTRA_ENV} != "none" ]; then
                    echo "source extra environment file"
                    source ${WORKSPACE}/${upgradeEnvFile} //this one create a tmp.txt file
                fi
                cat tmp.txt
                """
            rc = sh(script: runTest, returnStatus: true)

I met this issue:

Cannot contact KVM-66: java.io.FileNotFoundException: /home/coolboy/workspace/DemoJob@tmp/durable-451e7be4/jenkins-log.txt (Permission denied)

When I access to the KVM and ls it:

total 84
drwxrwxr-x 3 coolboy coolboy  4096 Nov 15 16:37 ..
-rw-rw-r-- 1 coolboy coolboy   652 Nov 15 16:37 script.sh
-rwx------ 1 root    coolboy 65849 Nov 15 16:37 jenkins-log.txt
-rw-rw-r-- 1 coolboy coolboy     2 Nov 15 16:37 jenkins-result.txt
drwxrwxr-x 2 coolboy coolboy  4096 Nov 15 16:37 .

Somehow, the owner of 'jenkins-log' is changed to root. And, the 'tmp.txt' is created successfully.

I've tried these: permission denied in jenkins pipeline running bash script Permission denied while running maven command jenkins

But none of these works. With the same job and configuration, it's always successful when running on ubuntu18.04. My versions:

  • Jenkins's version: 2.249.2
  • KVM OS: ubuntu20.04
  • Durable task's version: 1.35

I've set up new env with:

  • Jenkins version: 2.375.3
  • Durable task: 510.v324450f8dca_4

But still have the same issue.

Any idea? Thanks in advance

1

There are 1 best solutions below

1
Jeff Sloyer On

The file is question is owned by root not the current jenkins user. You could try running the following:

sudo root
chown coolboy:coolboy jenkins-log.txt