【问题标题】:Jenkins job getting stuck on execution of docker image as the agentJenkins 的工作卡在作为代理执行 docker 映像
【发布时间】:2020-02-21 02:34:36
【问题描述】:

我在虚拟机中安装了 Jenkins 和 Docker。我正在使用 Jenkins 管道项目,我的 jenkins 声明式管道看起来像这样。

pipeline {
    agent {
        docker { image 'node:7-alpine' }
    }
    stages {
        stage('Test') {
            steps {
                echo 'Hello Nodejs'
                sh 'node --version'
            }
        }
    }
}

这个链接https://jenkins.io/doc/book/pipeline/docker/是一个非常基本的管道

当我尝试构建我的 jenkins 作业时,它会打印 Hello Nodejs,但会卡在下一条指令,即执行 shell 命令。 5 分钟后,作业失败并出现此错误

process apparently never started in /var/lib/jenkins/workspace/MyProject@tmp/durable-c118923c
(running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
ERROR: script returned exit code -2

我不明白为什么它不执行 sh 命令。

如果我将其设为agent any,它将执行sh 命令。

【问题讨论】:

标签: docker jenkins jenkins-pipeline jenkins-plugins jenkins-declarative-pipeline


【解决方案1】:

我不确定它是否会有所帮助,但我记得默认情况下节点映像是在 root 帐户下启动的。 Jenkins 在启动容器时使用自己的 ID。所以,很可能,这是一个权限问题。尝试添加 -u 0 参数:

agent {
    docker {
        image 'node:7-alpine'
        args '-u 0'
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    • 2018-04-28
    • 2019-12-11
    • 2020-05-14
    • 2017-06-27
    • 1970-01-01
    相关资源
    最近更新 更多