Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-36568

workflow script node step cannot trigger build on specific node

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I have a Jenkins pipeline job called "TestPipeline". I want to trigger a build on 2 different slaves which labeled "tester1' and "tester2". And the pipeline script is quite simple here:

      node('tester1') {
          build 'test_job'
      }
      node('tester2') {
          build 'test_job'
      }
      

      However when I run the TestPipeline job, the "test_job" won't run on the nodes which I assigned. But run on random nodes instead.

      I'm wondering if I should set "Restrict where this project can be run" on my "test_job". So I set it to "tester" (The "tester" label contains both node "tester1" and "tester2"). But when I run the pipeline job again, the "test_job" runs on "tester2" twice. I should expect the job to run on "tester1" first and then run on "tester2".

      So the build job step runs regardless of node step?

        Attachments

          Issue Links

            Activity

            Hide
            akostadinov akostadinov added a comment -

            Jesse Glick,

            • have a job with label parameter
            • build manually => the default value of parameter is respected
            • build from a pipeline (without specifying this parameter) => job is built on a random node (i.e. the default value of the label parameter is not respected)

            And in the latter case, when you go to the executed build parameters, you see the label parameter with the default values. They just didn't take effect.

            But probably this is a separate issue so I will file one.

            Show
            akostadinov akostadinov added a comment - Jesse Glick , have a job with label parameter build manually => the default value of parameter is respected build from a pipeline (without specifying this parameter) => job is built on a random node (i.e. the default value of the label parameter is not respected) And in the latter case, when you go to the executed build parameters, you see the label parameter with the default values. They just didn't take effect. But probably this is a separate issue so I will file one.
            Hide
            grandma Roman Kovtyukh added a comment - - edited

            Cuong Tran, can you tell me then how exactly it works please? This page on github tells that in this code:

            node('master') {
                // as before
            }
            

            The parameter

            may be a node name, or a single label ...

             
            So, can you tell us how exactly we should use it?

            Show
            grandma Roman Kovtyukh added a comment - - edited Cuong Tran , can you tell me then how exactly it works please? This page on github tells that in this code: node( 'master' ) { // as before } The parameter may be a node name, or a single label ...   So, can you tell us how exactly we should use it?
            Hide
            ctran Cuong Tran added a comment -

            Roman, it's better to use the mailing list for general help question.

            Show
            ctran Cuong Tran added a comment - Roman, it's better to use the mailing list for general help question.
            Hide
            jernejg jernej goricki added a comment -

            Hi guys,

            1. Install Node and Label parameter plugin
            2. In test_job's configuration, select 'This build is parameterized' and add a Label parameter and set the parameter name to 'node'
            3. In pipeline script, use Cuong Tran's code:

            What if I would like to do step 2 in a parameterized scripted pipeline itself ?

            But I do not know how to define the label parameter. I tried the following:

            properties([[$class         : 'RebuildSettings',
                         autoRebuild    : false,
                         rebuildDisabled: false],
                         parameters([org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterDefinition(name: 'node')])])
            

             

            Show
            jernejg jernej goricki added a comment - Hi guys, Install  Node and Label parameter plugin In test_job's configuration, select 'This build is parameterized' and add a Label parameter and set the parameter name to 'node' In pipeline script, use  Cuong Tran 's code: What if I would like to do step 2 in a parameterized scripted pipeline itself ? But I do not know how to define the label parameter. I tried the following: properties([[$class : 'RebuildSettings' , autoRebuild : false , rebuildDisabled: false ], parameters([org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterDefinition(name: 'node' )])])  
            Hide
            jernejg jernej goricki added a comment -

            Ok to answer my own question...

             

            In my case I only needed a regular string parameter and then pass it into the node block like:

            ...
            string(defaultValue: '', description: 'select node', name: 'node')
            ...
            
            node(params.node) {}

            I'm sure I tried this before and it didn't work, so I thought I need to use the node/label plugin :/

            Show
            jernejg jernej goricki added a comment - Ok to answer my own question...   In my case I only needed a regular string parameter and then pass it into the node block like: ... string(defaultValue: '', description: ' select node ', name: ' node') ... node(params.node) {} I'm sure I tried this before and it didn't work, so I thought I need to use the node/label plugin :/

              People

              Assignee:
              jglick Jesse Glick
              Reporter:
              winnerwbx Andy Wang
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: