unable to run simple jenkins docker node build (home directories outside of /home are not currently supported)

2.5k Views Asked by At

I am using a very simple script mentioned below as per the official docs (https://www.jenkins.io/doc/book/pipeline/docker/):

pipeline {
    agent {
        docker { image 'node:14-alpine' }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

Simple as it is, it outputs follows:

22:58:45  [Pipeline] }
22:58:45  [Pipeline] // stage
22:58:45  [Pipeline] withEnv
22:58:45  [Pipeline] {
22:58:45  [Pipeline] isUnix
22:58:45  [Pipeline] sh
22:58:45  + docker inspect -f . node:14-alpine
22:58:46  Sorry, home directories outside of /home are not currently supported. 
22:58:46  See https://forum.snapcraft.io/t/11209 for details.
22:58:46  [Pipeline] isUnix
22:58:46  [Pipeline] sh
22:58:46  + docker pull node:14-alpine
22:58:46  Sorry, home directories outside of /home are not currently supported. 
22:58:46  See https://forum.snapcraft.io/t/11209 for details.
22:58:46  [Pipeline] }
22:58:46  [Pipeline] // withEnv
22:58:46  [Pipeline] }
22:58:46  [Pipeline] // node
22:58:46  [Pipeline] End of Pipeline
22:58:46  ERROR: script returned exit code 1
22:58:46  Finished: FAILURE

Not sure what I am doing wrong.

2

There are 2 best solutions below

0
On

The hyperlink inside the message leads to a page that says:

Snapd does currently not support running snaps if the home directory of the user is outside of /home.

It says that for the docker command. I suspect you're trying to run the docker command as the jenkins user. The default home directory for the jenkins user is /var/lib/jenkins. The default home directory of the jenkins user is outside /home.

If that's the case, there are several alternatives available:

  • Create a user on that computer with a home directory in /home and run a Jenkins agent as that user
  • Install docker on that computer using apt instead of using snapd (following the Docker directions rather than the Ubuntu directions)
  • Create a user on another computer with a home directory in /home and install docker there with snapd, then configure an agent to use that computer
1
On

It's likely you are inheriting the HOME environment variable from Jenkins in some way. You can use env config to override that. If you want the HOME from the worker node executing the docker build you can mount env.HOME into /home/jenkins (or something like that) into the container.

Something like:

pipeline {
    agent {
        docker {
            image 'node:14-alpine'
            args '-v $HOME:/home/jenkins'
        }
    }
    ...
}