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

Cannot restrict a matrix build job to one node/label

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • matrix-project-plugin
    • None
    • Jenkins ver. 1.562
      Matrix Project Plugin 1.2

      Got the Matrix Job set this under Advanced: "Restrict where this project can be run" to "master"
      But when I run the Matrix only the first job runs on the Master - the rest run on any of the Slaves available

          [JENKINS-23459] Cannot restrict a matrix build job to one node/label

          Reiner Wirtz added a comment -

          @Jordan Spiker: I don't understand the question. The master is the master of the jenkins installation. It isn't a slave.
          As far as I understand the call, the problem was to create for every object in a list a subjob and in this case to run all the subjobs on the master node of the jenkins installation.

          Reiner Wirtz added a comment - @Jordan Spiker: I don't understand the question. The master is the master of the jenkins installation. It isn't a slave. As far as I understand the call, the problem was to create for every object in a list a subjob and in this case to run all the subjobs on the master node of the jenkins installation.

          Habeeb FKR added a comment -

          I think I have the same need as @Jordan Spiker, instead of restriction on a node (master for example) I need to restrict builds to a Label.

          So the question is: can we use groovy to do such thing ?

          Thank you

          Habeeb FKR added a comment - I think I have the same need as @Jordan Spiker, instead of restriction on a node (master for example) I need to restrict builds to a Label. So the question is: can we use groovy to do such thing ? Thank you

          Reiner Wirtz added a comment -

          Have you read the help (question mark at the right side)?

          It starts as follow:

          Return value from Groovy script is treated as Label Expression. It is treated as followings:

          A non-string value will be converted to a string using toString()
          When null or blank string is returned, node restriction does not take effect (or is not overwritten).
          When exception occurred or Label Expression is not parsed correctly, builds are canceled.

          It sounds for me, that the return value "Master" from groovy script is treated as a label for the master node.
          But I haven't tried it in my environment.
          But if some else tested it, it would be nice to hear from him.

          Reiner Wirtz added a comment - Have you read the help (question mark at the right side)? It starts as follow: Return value from Groovy script is treated as Label Expression. It is treated as followings: A non-string value will be converted to a string using toString() When null or blank string is returned, node restriction does not take effect (or is not overwritten). When exception occurred or Label Expression is not parsed correctly, builds are canceled. It sounds for me, that the return value "Master" from groovy script is treated as a label for the master node. But I haven't tried it in my environment. But if some else tested it, it would be nice to hear from him.

          Peter Triesz added a comment -

          we also experience this with Jenkins ver. 1.612 too
          The "Restrict where this project can be run" setting is ignored for a Matrix config.

          The above workaround works though: installing the "Groovy Label Assignment plugin" and returning the Label of the desired node works OK.

          Peter Triesz added a comment - we also experience this with Jenkins ver. 1.612 too The "Restrict where this project can be run" setting is ignored for a Matrix config. The above workaround works though: installing the "Groovy Label Assignment plugin" and returning the Label of the desired node works OK.

          Mark Waite added a comment -

          As far as I understand the behavior, the "restrict where a project can be run" setting only controls the initial "flyweight job" which starts the multi-configuration job. The multi-configuration wiki page has a paragraph describing that behavior and references two plugins which can modify that behavior.

          Mark Waite added a comment - As far as I understand the behavior, the "restrict where a project can be run" setting only controls the initial "flyweight job" which starts the multi-configuration job. The multi-configuration wiki page has a paragraph describing that behavior and references two plugins which can modify that behavior.

          Reiner Wirtz added a comment - - edited

          @Peter: Thak You very much for the note, that a plugin is needed for the workaround

          Reiner Wirtz added a comment - - edited @Peter: Thak You very much for the note, that a plugin is needed for the workaround

          Mohamed Samy added a comment -

          I was able to achieve the desired behavior where I can restrict slave jobs to run on certain labels.

          I did the following:

          1. add the "label expression" axis then add an expression that filters what machines you want to run on
            1. the problem here is that this expression will be used in the workspace name so you have to change the workspace name to avoid run issues due to strange folder names
          2. "Use custom child workspace" : specify a unique name per run using the matrix axis names as variables

           

          Mohamed Samy added a comment - I was able to achieve the desired behavior where I can restrict slave jobs to run on certain labels. I did the following: add the "label expression" axis then add an expression that filters what machines you want to run on the problem here is that this expression will be used in the workspace name so you have to change the workspace name to avoid run issues due to strange folder names "Use custom child workspace" : specify a unique name per run using the matrix axis names as variables  

          Daniel Kang added a comment -

          shmoib can you share a screen shot of your configuration? 

          Daniel Kang added a comment - shmoib can you share a screen shot of your configuration? 

          Mohamed Samy added a comment -

          dakang, here you are

          1- add the "label expression" axis 

           

          2- "Use custom child workspace" : specify a unique name per run using the matrix axis names as variables

           

          Mohamed Samy added a comment - dakang , here you are 1- add the "label expression" axis    2- "Use custom child workspace" : specify a unique name per run using the matrix axis names as variables  

          Daniel Kang added a comment -

          thank you shmoib

          Daniel Kang added a comment - thank you shmoib

            kohsuke Kohsuke Kawaguchi
            giladj Gilad Judes
            Votes:
            19 Vote for this issue
            Watchers:
            22 Start watching this issue

              Created:
              Updated: