Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkinsfile and multiple nodes

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: "[email protected]",
                     replyTo: "[email protected]",
                        from: '[email protected]'
            }
        }
    }
}

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

How do I do that?

like image 302
Sardathrion - against SE abuse Avatar asked May 03 '17 15:05

Sardathrion - against SE abuse


1 Answers

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' 
    }
  }
}

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.

like image 112
burnettk Avatar answered Nov 04 '22 10:11

burnettk