npm install fails in jenkins pipeline in docker

前端 未结 12 910
野性不改
野性不改 2020-12-07 17:45

I\'m following a tutorial about Jenkins pipeline and I can get a \"hello world\" working under at node 6.10 docker container.

But, when I added a default EmberJS app

12条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 18:08

    Wanted to just provide a bit more detail, in short the accepted answer works but that I'm new to Docker and wanted to get a better understanding and figured i'd share what i found.

    So for our jenkins setup, it starts containers via

    docker run -t -d -u 995:315 -w /folder/forProject -v /folder/forProject:/folder/forProject:rw,z ...
    

    As a result this container is running as user uid=995 gid=315 groups=315

    Since the image I was using (circleci/node:latest) doesn’t have a user with this UID/GID, the user will not have a “home” folder and will only have permission on the mounted volume.

    When NPM commands are called it will try using that users home directory (for cache) and since that user wasn’t created on the image, the home directory gets set to / (default for linux?). So to get NPM to work correctly we simply point the containers HOME environment variable for the user to the current folder via the Jenkins file

    pipeline {
      agent none
      stages {
        stage('NPM Installs') {
          agent {
            docker {
                image 'circleci/node:latest'
            }
          }
          environment { HOME="." }
          ...
        }
      }
    }
    

    Thus giving the user the ability to create the required .npm folder in /folder/forProject/.npm

    Hopefully this is helpful to someone and if you see something that i got wrong please let me know :D

提交回复
热议问题