在不同节点上运行 Jenkins 阶段 [英] Run Jenkins stage on different nodes

查看:22
本文介绍了在不同节点上运行 Jenkins 阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下多分支管道架构的 Jenkinsfile

I have the following Jenkinsfile of a multibranch pipeline architecture

#!/usr/bin/groovy

pipeline {
    agent {
        node {
            label 'ubuntu'
            customWorkspace "/src/$BUILD_NUMBER"
        }
    }
    environment {
        SRC_DIR = "$WORKSPACE"
        BUILD_DIR="/build/$BUILD_NUMBER"
    }

    stages {
        stage('Build') {
            steps {
                dir(BUILD_DIR) {
                    sh '$SRC_DIR/build.sh'
                }
            }
        }

        stage('Test') {
            steps {
                dir(BUILD_DIR) {
                   sh '$SRC_DIR/test.sh'
                }
            }
        }
    }
}

我正在尝试在 Ubuntu 和 Red Hat 节点上并行运行构建"阶段,并且仅在 Ubuntu 节点上运行测试"阶段.

I am trying to run the 'Build' stage on Ubuntu and Red Hat nodes in parallel, and the 'Test' stage on the Ubuntu node only.

任何人都可以帮助我指定如何选择在哪些节点上运行哪个阶段.我在网上找到的解决方案很少,但他们建议重写构建阶段两次:一次用于 Red Hat 节点,另一次用于 Ubuntu 节点.没有代码重复就没有办法做到这一点吗?

Can anybody help me in specifying how to choose which stage are run on which nodes. I found few solutions online but they recommended rewriting the build stage twice: once for the Red Hat node and the other for the Ubuntu node. Isn't there a way to do this without code duplication ?

非常感谢

推荐答案

当然,你会想以某种方式标记你的从节点.基本上在 Jenkins 上配置所有节点并给它们起有意义的名称.

Sure, you would want to label your slave nodes somehow. Basically configure all the node on Jenkins and give them meaningful names.

  stage('Build') {
   steps {
     node('os_linux') {
       sh './build.sh' 
     }
     node('os_redhat') {
       sh './build.sh' 
   }
  }

这将串行运行任务,Jenkinsfile语法也支持在不同节点上并行执行命令.

This will run the tasks in serial, and Jenkinsfile syntax also supports executing commands in parallel on different nodes.

谢谢,

这篇关于在不同节点上运行 Jenkins 阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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