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

Allows variable subistution for Job 'Restrict where this project can be run' label expression

    • Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Icon: Major Major
    • core
    • Windows Server 2008 SP2

      Allow variable substitution for the 'Restrict where this project can be run' label expression field of the job configuration.

      Substitution of the form ${BRANCH} where BRANCH is a parameter to the job, will allow the job to run on any node with a label which matches BRANCH.

      Motivation.
      We have large branches which can take several hours to checkout from fresh. We therefore need to ensure that jobs are run on slaves which already have the branch checkedout in order to keep build times at acceptiable levels. Atm we have some Jobs which we need to be able to run on any branch, these jobs have a parameter BRANCH which is currently used to by the perforce plugin to set the correct depot path. Depending on the number of files which needs to be synced this can cause a significant delay in build times.
      The alternative is to duplicate the job and hardcode the node label for each branch, this solves the re-sync issue but causes duplicated jobs and a maintiance headache. Not to mention it clutters the interface and confuses the users.

      Having parameter subistution on the node label field would allow us to specify which slave group to use for which branches and then have Jenkins take care of all of the management.

      Hopefully this is a quick and easy feature to add.

      Many thanks

          [JENKINS-12998] Allows variable subistution for Job 'Restrict where this project can be run' label expression

          any chance of this getting in? i really hate having to replicate jobs just so they run on the correct hardware.

          schleprock

          william schilp added a comment - any chance of this getting in? i really hate having to replicate jobs just so they run on the correct hardware. schleprock

          Wren Weburg added a comment -

          This plugin actually provides parameter substitution in a direct way, just as you'd have expected Jenkins to do it natively: https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Label+Assignment+plugin

          To just have the label be based on a parameter called MY_PARAM, you'd use this one line of Groovy code:

          return binding.getVariables().get("MY_PARAM")

          Wren Weburg added a comment - This plugin actually provides parameter substitution in a direct way, just as you'd have expected Jenkins to do it natively: https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Label+Assignment+plugin To just have the label be based on a parameter called MY_PARAM, you'd use this one line of Groovy code: return binding.getVariables().get("MY_PARAM")

          Ryan Small added a comment -

          +1 I would love to pass a parameter from one job to the next, and assign that parameter value to a node label variable.

          Ryan Small added a comment - +1 I would love to pass a parameter from one job to the next, and assign that parameter value to a node label variable.

          Daniel Beck added a comment -

          Doesn't the NodeLabel Parameter plugin do the job? What's the rationale to request inclusion in core?

          Daniel Beck added a comment - Doesn't the NodeLabel Parameter plugin do the job? What's the rationale to request inclusion in core?

          Marc Carter added a comment -

          I'm using nodelabel for this but can see why this should be core functionality as it was a let down to find this out . The fact that nodelabel specifically competes with (rather than extends) the existing constraint system should be enough to tell you that something is "missing".

          Indeed as a general UX thing I first expected that I could use a ${parameter} anywhere that I could type text and was disappointed to find only some things supported it and some of those only seem to support it on the server-side whilst telling you it's invalid in the UI.

          Marc Carter added a comment - I'm using nodelabel for this but can see why this should be core functionality as it was a let down to find this out . The fact that nodelabel specifically competes with (rather than extends) the existing constraint system should be enough to tell you that something is "missing". Indeed as a general UX thing I first expected that I could use a ${parameter} anywhere that I could type text and was disappointed to find only some things supported it and some of those only seem to support it on the server-side whilst telling you it's invalid in the UI.

          Victor Lopez added a comment - - edited

          I'm having the same issue here..
          I have several nodes that can run a job, and I want to be able to specify through parameters whether it should be run by one specific node or that it doesn't matter which node runs it.

          I am trying to do it by assigning the label "any" to all the nodes, the job has a choice parameter containing all the node names plus the label "any", if the parameter is "any" all the nodes can execute this job.

          Nodelabel plugin doesn't allow me to do it, because it forces me to pick a node, and I cannot have the option to run it in any available node.

          edit:
          The situation I described above can be done with a Label paremeter from the NodeLabel plugin. It cannot display the node names and labels as a choice list, but they can be entered manually.

          Victor Lopez added a comment - - edited I'm having the same issue here.. I have several nodes that can run a job, and I want to be able to specify through parameters whether it should be run by one specific node or that it doesn't matter which node runs it. I am trying to do it by assigning the label "any" to all the nodes, the job has a choice parameter containing all the node names plus the label "any", if the parameter is "any" all the nodes can execute this job. Nodelabel plugin doesn't allow me to do it, because it forces me to pick a node, and I cannot have the option to run it in any available node. edit: The situation I described above can be done with a Label paremeter from the NodeLabel plugin. It cannot display the node names and labels as a choice list, but they can be entered manually.

          The same problem seems to be logged already here - https://issues.jenkins-ci.org/browse/JENKINS-9665. It also states to be resolved, so I guess this one is also done.

          Miroslav Nedyalkov added a comment - The same problem seems to be logged already here - https://issues.jenkins-ci.org/browse/JENKINS-9665 . It also states to be resolved, so I guess this one is also done.

          Daniel Beck added a comment - - edited

          Miroslav: The other issue was marked resolved because plugins solve it.

          It seems in this one users insist it be a core feature, despite extension points existing that support this and multiple plugins implementing those.


          Indeed as a general UX thing I first expected that I could use a ${parameter} anywhere that I could type text and was disappointed to find only some things supported it and some of those only seem to support it on the server-side whilst telling you it's invalid in the UI

          There will never be full support for variable replacement because it's specifically set up to be optional for any configuration options. So while it could be added to the label expression (in theory), it will not be the first step to unifying the behavior of everything.

          Daniel Beck added a comment - - edited Miroslav: The other issue was marked resolved because plugins solve it. It seems in this one users insist it be a core feature, despite extension points existing that support this and multiple plugins implementing those. Indeed as a general UX thing I first expected that I could use a ${parameter} anywhere that I could type text and was disappointed to find only some things supported it and some of those only seem to support it on the server-side whilst telling you it's invalid in the UI There will never be full support for variable replacement because it's specifically set up to be optional for any configuration options. So while it could be added to the label expression (in theory), it will not be the first step to unifying the behavior of everything.

          Daniel, thanks for the information. I guess we should stick to one of the plugins for the time being

          Miroslav Nedyalkov added a comment - Daniel, thanks for the information. I guess we should stick to one of the plugins for the time being

          As noted, there are defined extension points in core for this and plugins which implement them, so this won't be reimplemented in core.

          Christopher Orr added a comment - As noted, there are defined extension points in core for this and plugins which implement them, so this won't be reimplemented in core.

            Unassigned Unassigned
            richardtaylor Richard Taylor
            Votes:
            7 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: