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

Option to (abort,mark unstable, queue) if resouce(s) are unavailable.

    XMLWordPrintable

Details

    Description

      If job cannot lock resources, provide finer control, instead of just queuing. 

      options{
       lock( ifLocked:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
      }

       

      With timeout field  ? JENKINS-41699

      options{ 
        lock( timeout: 4, onTimeout:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
       }

       

      This pipeline demonstrates the desired effect, but is unusable inside the sandbox.

      /*
      First build acquires one of two locks. Second build acquires the second lock, but the resource check step aborts the job if all locks are used up. Additional builds will queue and eventually fall into one of the first two scenarios */
      
      //envLock = [envResource1, envResource2]
      //workspaceLock = [wsResource1, wsResouece2]
      
      import org.jenkins.plugins.lockableresources.LockableResourcesManager as LockMan 
      
      def envLock        = 'envLock'  
      def workspaceLock  = 'workSpaceLock'
      
      pipeline{
        options {
           lock(extra: [[label:envLock, quantity: 1], [label:workspaceLock, quantity: 1]])
        }
        stages {
           stage('Resource Availability Check'){
             when { expression  { LockMan.get().getFreeResourceAmount(envLock) == 0 || LockMan.get().getFreeResourceAmount(workspaceLock) == 0 } }
             steps{
               script{
                 currentBuild.result = 'ABORTED'
                 error('Some other Pipeline is already using the resources, please try again later.')
               }
             }
           }
          stage('Install/Update Tools'){
            steps{
              echo ("./gradlew install")
          }}
      }}

       

      Attachments

        Issue Links

          Activity

            truesoupfly Luis Tejada created issue -
            truesoupfly Luis Tejada made changes -
            Field Original Value New Value
            Description  

            If job cannot lock resources, provide finer control, instead of just queuing. 
            {code:java}

            options{
             lock( ifLocked:'abort' ,extra:[[resource:resource1],[resource:resource2]])
            }{code}
             

             
             

            If job cannot lock resources, provide finer control, instead of just queuing. 
            {code:java}
            options{
             lock( ifLocked:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
            }{code}
             

             
            truesoupfly Luis Tejada made changes -
            Link This issue is related to JENKINS-41699 [ JENKINS-41699 ]
            truesoupfly Luis Tejada made changes -
            Link This issue is related to JENKINS-48603 [ JENKINS-48603 ]
            truesoupfly Luis Tejada made changes -
            Description  

            If job cannot lock resources, provide finer control, instead of just queuing. 
            {code:java}
            options{
             lock( ifLocked:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
            }{code}
             

             
            If job cannot lock resources, provide finer control, instead of just queuing. 
            {code:java}
            options{
             lock( ifLocked:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
            }{code}
             

            With timeout field  ? JENKINS-41699
            {code:java}
            options{
              lock( timeout: 4, onTimeout:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
             }{code}
            truesoupfly Luis Tejada made changes -
            Description If job cannot lock resources, provide finer control, instead of just queuing. 
            {code:java}
            options{
             lock( ifLocked:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
            }{code}
             

            With timeout field  ? JENKINS-41699
            {code:java}
            options{
              lock( timeout: 4, onTimeout:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
             }{code}
            If job cannot lock resources, provide finer control, instead of just queuing. 
            {code:java}
            options{
             lock( ifLocked:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
            }{code}
             

            With timeout field  ? JENKINS-41699
            {code:java}
            options{
              lock( timeout: 4, onTimeout:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
             }{code}


            This pipeline demonstrates the desired effect, but is unusable inside the sandbox.
            {code:java}
            //envLock = [envResource1, envResource2]
            //workspaceLock = [wsResource1, wsResouece2]
             
            pipeline{
              options {
                 lock(extra: [[label:envLock, quantity: 1], [label:workspaceLock, quantity: 1]])
              }
              stages {
                 stage('Resource Availability Check'){
                   when { expression { LockMan.get().getFreeResourceAmount(envLock) == 0 || LockMan.get().getFreeResourceAmount(workspaceLock) == 0 } }
                   steps{
                     script{
                       currentBuild.result = 'ABORTED'
                       error('Some other Pipeline is already using the resources, please try again later.')
                     }
                   }
                 }
                stage('Install/Update Tools'){
                  steps{
                    echo ("./gradlew install")
                }}
            }}{code}
             
            truesoupfly Luis Tejada made changes -
            Description If job cannot lock resources, provide finer control, instead of just queuing. 
            {code:java}
            options{
             lock( ifLocked:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
            }{code}
             

            With timeout field  ? JENKINS-41699
            {code:java}
            options{
              lock( timeout: 4, onTimeout:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
             }{code}


            This pipeline demonstrates the desired effect, but is unusable inside the sandbox.
            {code:java}
            //envLock = [envResource1, envResource2]
            //workspaceLock = [wsResource1, wsResouece2]
             
            pipeline{
              options {
                 lock(extra: [[label:envLock, quantity: 1], [label:workspaceLock, quantity: 1]])
              }
              stages {
                 stage('Resource Availability Check'){
                   when { expression { LockMan.get().getFreeResourceAmount(envLock) == 0 || LockMan.get().getFreeResourceAmount(workspaceLock) == 0 } }
                   steps{
                     script{
                       currentBuild.result = 'ABORTED'
                       error('Some other Pipeline is already using the resources, please try again later.')
                     }
                   }
                 }
                stage('Install/Update Tools'){
                  steps{
                    echo ("./gradlew install")
                }}
            }}{code}
             
            If job cannot lock resources, provide finer control, instead of just queuing. 
            {code:java}
            options{
             lock( ifLocked:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
            }{code}
             

            With timeout field  ? JENKINS-41699
            {code:java}
            options{
              lock( timeout: 4, onTimeout:'abort' ,extra:[[resource:'resource1'],[resource:'resource2']])
             }{code}
             

            This pipeline demonstrates the desired effect, but is unusable inside the sandbox.
            {code:java}
            /*
            First build acquires one of two locks. Second build acquires the second lock, but the resource check step aborts the job if all locks are used up. Additional builds will queue and eventually fall into one of the first two scenarios */

            //envLock = [envResource1, envResource2]
            //workspaceLock = [wsResource1, wsResouece2]

            import org.jenkins.plugins.lockableresources.LockableResourcesManager as LockMan

            def envLock    = 'envLock'  
            def workspaceLock  = 'workSpaceLock'

            pipeline{
              options {
                 lock(extra: [[label:envLock, quantity: 1], [label:workspaceLock, quantity: 1]])
              }
              stages {
                 stage('Resource Availability Check'){
                   when { expression { LockMan.get().getFreeResourceAmount(envLock) == 0 || LockMan.get().getFreeResourceAmount(workspaceLock) == 0 } }
                   steps{
                     script{
                       currentBuild.result = 'ABORTED'
                       error('Some other Pipeline is already using the resources, please try again later.')
                     }
                   }
                 }
                stage('Install/Update Tools'){
                  steps{
                    echo ("./gradlew install")
                }}
            }}{code}
             

            People

              Unassigned Unassigned
              truesoupfly Luis Tejada
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: