Wednesday, December 4, 2019

jenkins-log.txt Permission denied

I started getting the error below, after recreating Jenkins setup thru helm charts. At the beginning I thought I had missed to install a plugin, or installed one that corrupted Jenkins pipelines. So after starting from scratch I could not find why it was working before and then got broken.

sh: 1: cannot create /home/jenkins/agent/workspace/myproject/durable-48fa5881/jenkins-log.txt: Permission denied

So after reading a thread on Jenkins blog; I realized that "Jenkins" user is being used by Jenkins, and I was using "myuser" in my pod. So, I changed everything in my Dockerfile to match Jenkins slave image, like the following:

RUN groupadd --gid 10000 jenkins && useradd --gid 10000 --uid 10000 jenkins --shell /bin/bash
RUN mkdir /home/jenkins && chown -R jenkins:jenkins /home/jenkins
USER jenkins
WORKDIR /home/jenkins

After that, the permission denied error went away. I am still wondering how this was working before...