Jenkins pipeline gives PermissionError: [Errno 13] Permission denied when writing global config file

I am attempting to run a Jenkins pipeline in a Docker container. However, I keep getting a permission error when I do so. I have tried changing the owner and group of the workspace directory to jenkins, as well as giving jenkins full rwx access. More information about the error can be found in the link below.
https://stackoverflow.com/questions/75717563/jenkins-pipeline-gives-permissionerror-errno-13-permission-denied-when-writin

I’ve been putting off replying cause I don’t have time for explanations.

Short answer is your need to set the HOME env to something. Probably env.WORKSPACE

I
If you copy your question here I’ll try and quote and provide to provide contact

1 Like

Hello @nicktsan and welcome to this community :wave:

Here are a few suggestions you can try:

  1. Make sure that the Docker container is running with the same user and group ID as the jenkins user on the host machine. You can specify this by adding the --user flag to your docker run command. For example, if the jenkins user has a user ID of 1000 and a group ID of 1000, you can run the container with the following command:
docker run --user 1000:1000 my-image
  1. Check the permissions on the file or directory that the pipeline is trying to write to. Make sure that the jenkins user has write access to that file or directory. You can change the permissions with the chmod command. For example, to give the jenkins user full access to a directory, you can run the following command:
chmod -R 777 /path/to/directory
  1. If the pipeline is trying to write to a file or directory inside the container, make sure that the container has write access to that file or directory. You can specify this by adding a VOLUME directive to your Dockerfile. For example:
VOLUME /path/to/directory
  1. If you are using a Dockerfile to build the image, make sure that you are running the commands that write to the file or directory as the jenkins user. You can use the USER directive to switch to the jenkins user before running those commands. For example:
USER jenkins
RUN echo "Hello, world" > /path/to/file

Hopefully one of these suggestions helps resolve your permission error.