Jenkinsfile 和多个节点

2023-12-20

我有一些需要运行的代码(实际上是构建、测试和包,但例如只是运行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: "[email protected] /cdn-cgi/l/email-protection",
                     replyTo: "[email protected] /cdn-cgi/l/email-protection",
                        from: '[email protected] /cdn-cgi/l/email-protection'
            }
        }
    }
}

中间一点,我想在两个不同的上运行nodes: 一个用于操作系统 1,一个用于操作系统 2。

我怎么做?


当然,您可能希望以某种方式标记您的从属节点。我没有查 tox 是什么,但也许像“os_linux”和“os_mac”,然后你可以使用node步骤在 Jenkinsfile 中,在每个从站的上下文中运行一些命令。所以您的 Tox 阶段可能如下所示:

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Jenkinsfile 和多个节点 的相关文章

随机推荐