Having a Jenkins Docker image, I would like to add the complete 'npm' environment to that image. So after building the Dockerfile I have an image with both Jenkins and the 'npm' environment.
The purpose is that a Jenkins job to run the shell command 'npm'. So 'npm' should be on the $PATH (in Ubuntu).
I have already a Dockerfile with a lot stuff in there like Jenkins and Maven.
A solution for node was described in this post. The important thing is, can I do something simular? Which folders should I copy to the Jenkins docker image?
FROM node as nodejs
FROM jenkins/jenkins
// All kinds of other stuff goes here
COPY --from=nodejs /usr/local/bin/node /usr/local/bin/node ???
Installing 'npm' automatically within a Jenkins Global tool is not my preferred solution.
Using multiple
FROM
directives is not a feature, it's a bug. It's proposed to remove it and you should avoid using itIf you need npm in your jenkins, just install it there. It's based on
openjdk
image anyway.I went into the same problem some time ago. In my case it turned out that it is better to use a throw-away containers with proper volumes instead of using a installed node/npm in the container with Jenkins.
Why? It turned out that many different version of npm have been used across the time. Setting up two versions of npm is possible of course (take a look at https://github.com/creationix/nvm) but the best solution I've chosen was that: https://getintodevops.com/blog/the-simple-way-to-run-docker-in-docker-for-ci.
However, please take notice that it was my case with my projects. I used docker inside the Jenkins container so that it was possible to use anything by using a job configuration (or later - Jenkinsfiles).