It would be something like:

      lock (resources: "my-res", timeout: 5) {
         [real work here]
      }
      

      So it tries to lock the resource and give up after 5 seconds.

          [JENKINS-41699] Add a timeout field

          Daniel Beck added a comment -

          This would be fantastic.

          My use case is in https://github.com/jenkins-infra/github-reports/ with two parallel blocks:

          • One takes seconds and should be executed every few minutes, which is the cron schedule of the full pipeline.
          • One takes a few hours to finish

          I am planning to combine a timeout for the entire pipeline with a lock around the long running command and inverse precedence, but it would be much nicer to be able to just skip this part of the pipeline if the resource is still locked.

          AFAIUI, there's currently no way to check for the state of a lock (to combine with declarative "when" block), or timeout the wait for a lock, specifically.

          Daniel Beck added a comment - This would be fantastic. My use case is in https://github.com/jenkins-infra/github-reports/ with two parallel blocks: One takes seconds and should be executed every few minutes, which is the cron schedule of the full pipeline. One takes a few hours to finish I am planning to combine a timeout for the entire pipeline with a lock around the long running command and inverse precedence, but it would be much nicer to be able to just skip this part of the pipeline if the resource is still locked. AFAIUI, there's currently no way to check for the state of a lock (to combine with declarative "when" block), or timeout the wait for a lock, specifically.

            amuniz Antonio Muñiz
            amuniz Antonio Muñiz
            Votes:
            7 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: