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

Add option to Fail the build if node label does not exist or if it cannot be provisioned within a timeout

    Details

    • Type: New Feature
    • Status: Reopened (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: plugin-proposals
    • Labels:
      None
    • Environment:
      Jenkins 1.642
      github-branch-source-plugin:1.7
      github-organization-folder-plugin:1.3
    • Similar Issues:

      Description

      Issue

      When a node label does not exists, the build hangs in the queue until a node is assigned to that label. In that case I would like my build to fail. It would be great to have such option and also the possibility to apply it with GitHub Organization.

      How to Reproduce

      node ('thislabeldoesnotexists') {
          echo "This could be improved"
      }
      

      This label does not exists in my Instance, the build hang in the queue and the console logs show:

      > There are no nodes with the label ‘thislabeldoesnotexists’

        Attachments

          Issue Links

            Activity

            Hide
            oleg_nenashev Oleg Nenashev added a comment -

            Since Jesse Glick disagrees, I have moved it to plugin proposals

            Show
            oleg_nenashev Oleg Nenashev added a comment - Since Jesse Glick disagrees, I have moved it to plugin proposals
            Hide
            hrmpw Patrick Wolf added a comment -

            From Jesse Glick:
            `ExecutorStepExecution.CancelledItemListener` could check `User.current` and if not null, print a message indicating what user cancelled the item, thus resulting in the build failure. Not sure it would help anything, but would at least be very easy to implement!

            Show
            hrmpw Patrick Wolf added a comment - From Jesse Glick : `ExecutorStepExecution.CancelledItemListener` could check `User.current` and if not null, print a message indicating what user cancelled the item, thus resulting in the build failure. Not sure it would help anything, but would at least be very easy to implement!
            Hide
            alexander_kazakov Aleksandr Kazakov added a comment -

            For anyone who's struggling with this issue - we use a workaround. We use it for cloud providers but it can be adjusted and used for static slave nodes as well.

            We didn't use it in declarative pipeline, but I think this approach can be applied to it too. 

            We have a script in our shared library vars/node.groovy:

             

            import org.jenkinsci.plugins.workflow.cps.DSL
            import hudson.model.Label
            import jenkins.model.Label
            import antlr.ANTLRException
            
            @NonCPS
            String checkLabel(String labelExpression) {
                String errorMessage = ''
                def clouds = Jenkins.instance.clouds
                if (clouds) {
                    try {
                        def label = Label.parseExpression(labelExpression)
                        def labelMatchedCloud = clouds.find { it.canProvision(label) }
                        if (!labelMatchedCloud) {
                            errorMessage = "Cannot find a node with label ${labelExpression}"
                        }
                    } catch (ANTLRException e) {
                        errorMessage = "Invalid node label expression:\n${e.message}"
                    }
                }
            
                return errorMessage
            }
            
            def call(Closure body) {
                error """No label specified.
            Usage:
            node('<<you_label_1>> && <<your_label_2>>') {
                ...
            }"""
            }
            
            def call(String label, Closure body) {
                def errorMessage = checkLabel(label)
                if (errorMessage) {
                    error errorMessage
                }
                
                DSL steps = getBinding().getVariable('steps') as DSL
                steps.invokeMethod('node', [label, body] as Object[])
            }

            Jenkinsfile

             

            @Library('myFancyLibrary@version')
            
            node('label1 && label2') {
                // method from the lib is used ...
            }

             

             

             

            Show
            alexander_kazakov Aleksandr Kazakov added a comment - For anyone who's struggling with this issue - we use a workaround. We use it for cloud providers but it can be adjusted and used for static slave nodes as well. We didn't use it in declarative pipeline, but I think this approach can be applied to it too.  We have a script in our shared library vars/node.groovy:   import org.jenkinsci.plugins.workflow.cps.DSL import hudson.model.Label import jenkins.model.Label import antlr.ANTLRException @NonCPS String checkLabel( String labelExpression) { String errorMessage = '' def clouds = Jenkins.instance.clouds if (clouds) { try { def label = Label.parseExpression(labelExpression) def labelMatchedCloud = clouds.find { it.canProvision(label) } if (!labelMatchedCloud) { errorMessage = "Cannot find a node with label ${labelExpression}" } } catch (ANTLRException e) { errorMessage = "Invalid node label expression:\n${e.message}" } } return errorMessage } def call(Closure body) { error """No label specified. Usage: node( '<<you_label_1>> && <<your_label_2>>' ) { ... }""" } def call( String label, Closure body) { def errorMessage = checkLabel(label) if (errorMessage) { error errorMessage } DSL steps = getBinding().getVariable( 'steps' ) as DSL steps.invokeMethod( 'node' , [label, body] as Object []) } Jenkinsfile   @Library( 'myFancyLibrary@version' ) node( 'label1 && label2' ) { // method from the lib is used ... }      
            Hide
            asreekumar Adity Sreekumar added a comment -

            We are facing this issue currently on our builds as well on occasion as we migrate jobs from one jenkins server to another which is accompanied with associated node relabeling and addition of new nodes. What I thought made sense was if the timeout could be applied to the pipeline as a whole and not just a step.

            Show
            asreekumar Adity Sreekumar added a comment - We are facing this issue currently on our builds as well on occasion as we migrate jobs from one jenkins server to another which is accompanied with associated node relabeling and addition of new nodes. What I thought made sense was if the timeout could be applied to the pipeline as a whole and not just a step.
            Hide
            amidar Amit Dar added a comment -

            This option is a high valuable option for organizations using a main jenkins server handling jobs for various development and integration groups.

            this way, a job waiting for execution would be automatically removed from the build queue after a pre-defined time for machine provisioning and the built queue will stay "clean". a notification with the reason should also be viewable in the console output of the execution (though it was not executed at all...).

            Show
            amidar Amit Dar added a comment - This option is a high valuable option for organizations using a main jenkins server handling jobs for various development and integration groups. this way, a job waiting for execution would be automatically removed from the build queue after a pre-defined time for machine provisioning and the built queue will stay "clean". a notification with the reason should also be viewable in the console output of the execution (though it was not executed at all...).

              People

              • Assignee:
                Unassigned
                Reporter:
                allan_burdajewicz Allan BURDAJEWICZ
              • Votes:
                6 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                • Created:
                  Updated: