Project

Profile

Help

How to make all sub-jobs to be executed on the same slave or master node which its parent was executed on

Overview

This wiki page will walk you through configuring sub-jobs to be executed on the same node as its parent

How it's done in jenkins

For section like 'Trigger/call builds on other projects' one can add next parameter 'Build on the same node' for using parents node.

How it's done via xml configuration

For builders sections

Usually sub-jobs is triggered with this options - http://docs.openstack.org/infra/jenkins-job-builder/builders.html#builders.trigger-builds. And it has parameter - 'same-node' which is must be set to true so this triggered job can use parents node

builders:
  - trigger-builds:
      - project: "build_started" 
        same-node: true

If we use multijob http://docs.openstack.org/infra/jenkins-job-builder/builders.html#builders.multijob, then we need to add parameter 'node-parameters' and set it to true. UPDATE IT DOES NOT WORK (SOLUTION IS BELOW)
We can use raw implementation (in example is builders where two multijob are created and they have 'node-parameters' enabled):

builders:
      - raw:
          xml: |
            <com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
              <phaseName>build</phaseName>
              <phaseJobs>
                <com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
                  <jobName>7798_build</jobName>
                  <currParams>true</currParams>
                  <configs>
                    <hudson.plugins.parameterizedtrigger.NodeParameters plugin="parameterized-trigger@2.29"/>
                  </configs>
                </com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
              </phaseJobs>
            </com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
      - raw:
          xml: |
            <com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
              <phaseName>performance_test</phaseName>
              <phaseJobs>
                <com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
                  <jobName>7798_performance_test</jobName>
                  <currParams>true</currParams>
                  <configs>
                    <hudson.plugins.parameterizedtrigger.NodeParameters plugin="parameterized-trigger@2.29"/>
                  </configs>
                </com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
              </phaseJobs>
            </com.tikal.jenkins.plugins.multijob.MultiJobBuilder>

Maybe that '' may vary from version to version.

To get that implementation we need to get our job in xml format. We can do that using JENKINS REST API like that:

http://JENKINS_URL/job/JOB_NAME/config.xml

Notice if for 'raw' implementation happens NPE then just clean workspace (https://groups.google.com/forum/#!msg/jenkinsci-issues/M46SjGUn65U/Ex-FAAFlCQAJ)

For publishers sections

Usually sub-jobs is triggered with this options - http://docs.openstack.org/infra/jenkins-job-builder/publishers.html#publishers.trigger-parameterized-builds. And it has parameter - 'node-parameters' which is must be set to true so this triggered job can use parents node

publishers:
  - trigger-parameterized-builds:
      - project: 'test-project-same-node'
        node-parameters: true