I am trying to follow the instructions found on the pnpm continuous integration page (see link in gh discussion) to use the pnpm package manager for node projects. I started a discussion here Usage with Jenkins · pnpm · Discussion #6869 · GitHub but I don’t expect there to be too many Jenkins experts on the pnpm issues board.
I’m having some permissions issues when running the following in my build script:
sh 'corepack prepare pnpm@latest-8 --activate'
The entirety of my jenkinsfile can be seen here
The error is from the jenkins user on my agent trying to write to directories outside the workspace it seems:
- corepack prepare pnpm@latest-8 --activate
Preparing pnpm@latest-8 for immediate activation…
Internal Error: EACCES: permission denied, mkdir ‘/.cache/node/corepack’
at mkdirSync (node:fs:1398:3)
Running jenkins agent locally using Mac OSX and Docker.
Jenkins version 2.401.3
The issue seems to be that the
HOME environment variables aren’t set, hence the ‘/.cache/node/corepack’ folder.
See GitHub - nodejs/corepack: Zero-runtime-dependency package acting as bridge between Node projects and their package managers, corepack expects it to be set as it will use it (
Suggestion, in your pipeline set the
COREPACK_HOME env var to
Thank you for the help. I tried setting COREPACK_HOME to JENKINS_HOME, and from what I can see, the
/var/jenkins_home dir does not exist. When I try to
ls it in the script, I get the error:
ls: cannot access ‘/var/jenkins_home/’: No such file or directory
I would set it to
WORKSPACE_TMP then (see /env-vars.html/)
You can also check in a pipeline the current folder with something like
I realize the issue is happening because my agent doesn’t know about /var/jenkins_home. I saw a SO post indicating that in the Jenkinsfile, you can set args to tell the docker container to mount a volume. In the
agent | docker section, I added:
args '--volume jenkins-pnpm:/var/jenkins_home:rw'
where jenkins-pnpm is a docker volume I created on my host machine.
When I run
ls -l /var/jenkins_home now, I see that the current directory exists, but it is owned by
root:root and only has write perms for the owner.
I haven’t been able to get past that issue.
The crux of the issue is that my user running the agent is id=502, which does not exist on the agent container. Maybe I need some more args?