简体   繁体   English

无法运行简单的 jenkins docker 节点构建(当前不支持 /home 之外的主目录)

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

I am using a very simple script mentioned below as per the official docs ( https://www.jenkins.io/doc/book/pipeline/docker/ ):根据官方文档( 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.不知道我做错了什么。

It's likely you are inheriting the HOME environment variable from Jenkins in some way.您可能以某种方式从 Jenkins 继承了 HOME 环境变量。 You can use env config to override that.您可以使用 env config 来覆盖它。 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.如果您希望来自执行 docker 构建的工作节点的 HOME,您可以将 env.HOME 挂载到 /home/jenkins(或类似的东西)到容器中。

Something like:就像是:

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

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.如果用户的主目录位于 /home 之外,则 Snapd 当前不支持运行快照。

It says that for the docker command.它说对于docker命令。 I suspect you're trying to run the docker command as the jenkins user.我怀疑您正在尝试以jenkins用户身份运行docker命令。 The default home directory for the jenkins user is /var/lib/jenkins . jenkins用户的默认主目录是/var/lib/jenkins The default home directory of the jenkins user is outside /home . jenkins用户的默认主目录位于/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在该计算机上使用/home中的主目录创建一个用户,并以该用户身份运行 Jenkins 代理
  • Install docker on that computer using apt instead of using snapd (following the Docker directions rather than the Ubuntu directions)使用apt而不是 snapd 在该计算机上安装snapd (遵循 Docker 方向而不是 Ubuntu 方向)
  • 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在另一台计算机上创建一个用户,其主目录位于/home并使用 snapd 安装snapd ,然后配置代理以使用该计算机

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM