Jenkinsfile和多个节点

时间:2017-05-03 15:35:38

标签: jenkins jenkins-pipeline

我有一些代码需要在不同的操作系统上运行(实际构建,测试和包,但仅举例来说,只运行tox)。目前我的Jenkinsfile看起来像这样:

pipeline {

    // Where to run stuff.
    agent { 
        node {
            label 'CentOS7' 
            customWorkspace '/home/build/jenkins/workspace/pipelines/ook'
        }
    }

    // What to run goes here.
    stages {
        stage('Tox') {
            steps {
                sh 'tox -v --recreate' 
            }
        }
    }

    // Clean up after ourselves.
    post {
        failure {
            mail subject: "\u2639 ${env.JOB_NAME} (${env.BUILD_NUMBER}) has failed",
                    body: """Build ${env.BUILD_URL} is failing!
    Somebody should do something about that\u2026""",
                          to: "devs@example.com",
                     replyTo: "devs@example.com",
                        from: 'jenkins@example.com'
            }
        }
    }
}

中间位,我想在两个不同的nodes上运行:一个用于OS 1,另一个用于OS 2.

我该怎么做?

1 个答案:

答案 0 :(得分:5)

当然,你想要以某种方式标记你的从属节点。我没有查找tox是什么,但可能喜欢'os_linux'和'os_mac',然后你可以使用Jenkinsfile中的node步骤在每个slave的上下文中运行一些命令。所以你的Tox阶段可能如下:

stage('Tox') {
  steps {
    node('os_linux') {
      sh 'tox -v --recreate' 
    }
    node('os_mac') {
      sh 'tox -v --recreate' 
    }
  }
}

这将以串行方式运行任务,并且Jenkinsfile语法还支持在不同节点上并行执行这两个tox命令。使用Jenkins UI左侧导航栏中的“管道语法”链接(仅限管道作业)来使用nodeparallel。摇滚。