Jenkinsfile 和多个节点 [英] Jenkinsfile and multiple nodes

查看:68
本文介绍了Jenkinsfile 和多个节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have some code that needs running (build, test, and packages in actuality but for example just running tox) on different OSes. Currently my Jenkinsfile looks like thus:

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 thatu2026""",
                          to: "devs@example.com",
                     replyTo: "devs@example.com",
                        from: 'jenkins@example.com'
            }
        }
    }
}

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

The middle bit, I want to run on two different nodes: one for OS 1 and one for OS 2.

我该怎么做?

推荐答案

当然,你会想以某种方式标记你的从节点.我没有查看 tox 是什么,但可能类似于 'os_linux' 和 'os_mac',然后您可以使用 Jenkinsfile 中的 node 步骤在每个从站的上下文中运行一些命令.因此,您的 Tox 阶段可能如下所示:

Sure, you would want to label your slave nodes somehow. I didn't look up what tox is, but maybe like 'os_linux' and 'os_mac', and then you can use the node step in your Jenkinsfile to run some commands in the context of each slave. So your Tox stage might look like:

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

这将串行运行任务,Jenkinsfile 语法还支持在不同节点上并行执行这两个 tox 命令.使用 Jenkins UI 左侧导航中的管道语法"链接(仅适用于管道作业)来玩弄 nodeparallel.摇滚吧.

This will run the tasks in serial, and Jenkinsfile syntax also supports doing those two tox commands in parallel on different nodes. Use the "Pipeline Syntax" link in the left nav of your Jenkins UI (only on pipeline jobs) to play around with node and parallel. Rock on.

这篇关于Jenkinsfile 和多个节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆