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

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

问题描述

我有一些需要在不同的OS上运行的代码(实际上是构建,测试和软件包,但例如仅运行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 that\u2026""",
                          to: "devs@example.com",
                     replyTo: "devs@example.com",
                        from: 'jenkins@example.com'
            }
        }
    }
}

中间,我想在两个不同的nodes上运行:一个用于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天全站免登陆