首页 文章

使用docker为Jenkins构建从属节点配置节点

提问于
浏览
1

我已经将我的Jenkins主机配置为使用docker,我可以连接到docker,我有一个简单的管道来测试它:

node ('docker-build-slave') {
    stage ('On slave') {
        sh 'ls -l'
        sh 'uname -a'
    }
}

当我发起构建并查看写入控制台的内容时,我得到:

由用户启动chris adkin [Pipeline]节点仍在等待计划任务标签'docker-build-slave'的所有节点都处于脱机状态

它只是挂起,我想知道是否有一些非常明显的我错过了,我是否需要为我的docker构建奴隶创建一个节点?

如果我进入托管jenkins的机器,我可以看到构建从属容器已经启动 .

3 回答

  • 1

    您提供的 docker-build-slave 是一个过滤可用Jenkins代理(主/从)的标签 . 如果没有将此标签分配给主服务器或任何(可用)从服务器,则无法构建此作业 . 了解更多关于labels的信息

    要让Jenkins管道使用 docker 全局变量,例如如this example中所述:

    node {
        checkout scm
        /*
         * In order to communicate with the MySQL server, this Pipeline explicitly
         * maps the port (`3306`) to a known port on the host machine.
         */
        docker.image('mysql:5').withRun('-e "MYSQL_ROOT_PASSWORD=my-secret-pw" -p 3306:3306') { c ->
            /* Run some tests which require MySQL */
            sh 'make check'
        }
    }
    
  • 0

    所以经过一些挖掘,我回答自己的问题有点羞耻,我偶然发现了这篇Jenkins的文章:

    https://issues.jenkins-ci.org/browse/JENKINS-44859

    文章指出,我使用Java JDK 7构建了我的图像,并引用了Vinson Lee添加的评论:

    Jenkins 2.54需要Java 8 .

    我为我的图像修改了docker文件以安装open jdk 8,现在一切正常 .

  • 0

    修复工作正常,这是成功运行构建作业的控制台输出:

    Started by user chris adkin
    [Pipeline] node
    Still waiting to schedule task
    All nodes of label ‘docker-build-slave’ are offline
    Running on docker-13b5a18eb067 in /home/jenkins/workspace/Pipeline With Docker Slave
    [Pipeline] {
    [Pipeline] stage
    [Pipeline] { (On slave)
    [Pipeline] sh
    [Pipeline With Docker Slave] Running shell script
    + ls -l
    total 0
    [Pipeline] sh
    [Pipeline With Docker Slave] Running shell script
    + uname -a
    Linux localhost 4.9.49-moby #1 SMP Wed Sep 27 00:36:29 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    Finished: SUCCESS
    

相关问题