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

Provide pipeline example that enables timestamper if is available

    XMLWordPrintable

Details

    Description

      While this may sound like an unimportant feature request I think it would really be nice if we could have some jenkins pipeline code that is loading the timestamper if is available and if not just running the same block without it.

      Can we have such an example?

      PS. I was a real pleasure to see the new DLS syntax from version 1.8. Thanks.

      Attachments

        Activity

          The timestamps() option does not work in declarative pipeline:

          org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
          WorkflowScript: 20: Invalid option type "timestamps". Valid option types: [ansiColor, authorizationMatrix, buildDiscarder, catchError, checkoutToSubdirectory, copyArtifactPermission, disableConcurrentBuilds, disableResume, durabilityHint, lock, newContainerPerStage, office365ConnectorWebhooks, overrideIndexTriggers, parallelsAlwaysFailFast, preserveStashes, quietPeriod, rateLimitBuilds, retry, script, skipDefaultCheckout, skipStagesAfterUnstable, task, timeout, waitUntil, withContext, withCredentials, withEnv, ws] @ line 20, column 2.

          timestamps ()

          ^1 error

          dbsanfte David Sanftenberg added a comment - The timestamps() option does not work in declarative pipeline: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 20: Invalid option type "timestamps". Valid option types: [ansiColor, authorizationMatrix, buildDiscarder, catchError, checkoutToSubdirectory, copyArtifactPermission, disableConcurrentBuilds, disableResume, durabilityHint, lock, newContainerPerStage, office365ConnectorWebhooks, overrideIndexTriggers, parallelsAlwaysFailFast, preserveStashes, quietPeriod, rateLimitBuilds, retry, script, skipDefaultCheckout, skipStagesAfterUnstable, task, timeout, waitUntil, withContext, withCredentials, withEnv, ws] @ line 20, column 2. timestamps () ^ 1 error

          I also think it's a pain to repeat all those options. Its a textbook example of boilerplate.

          In regular scripted pipeline you can at least use the code-sharing to have a common wrapper (and use reflection to enable things if available), but there seems to be no solution for declarative syntax

          jbochenski Jakub Bochenski added a comment - I also think it's a pain to repeat all those options. Its a textbook example of boilerplate. In regular scripted pipeline you can at least use the code-sharing to have a common wrapper (and use reflection to enable things if available), but there seems to be no solution for declarative syntax
          ssbarnea Sorin Sbarnea added a comment -

          Thanks, this documents very well the new declarative-pipeline syntax (the... 5th, of 6th way of writing jobs in jenkins is i count well.)

          What I was looking for was a way to enable the timestamps (or other wrappers in non-scripted pilelines in a way that degrade gracefully).

          Here is the deal: most wrappers if (not even all), do add some extra functionality without which the job would probably still be able to run. 

          What would be very powerful would be to have some kind of way to do enable the wrapper if installed or ignore that.

           

          ssbarnea Sorin Sbarnea added a comment - Thanks, this documents very well the new declarative-pipeline syntax (the... 5th, of 6th way of writing jobs in jenkins is i count well.) What I was looking for was a way to enable the timestamps (or other wrappers in non-scripted pilelines in a way that degrade gracefully). Here is the deal: most wrappers if (not even all), do add some extra functionality without which the job would probably still be able to run.  What would be very powerful would be to have some kind of way to do enable the wrapper if installed or ignore that.  
          quas Jakub Pawlinski added a comment - - edited

          based on https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Syntax-Reference 

          you just have to set in pipeline:
           

          options { timestamps() }

           and yes, it works

          quas Jakub Pawlinski added a comment - - edited based on  https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Syntax-Reference   you just have to set in pipeline:   options { timestamps() }  and yes, it works
          ssbarnea Sorin Sbarnea added a comment -

          I am really interested about this subject because all these wrappers like: timestamper, ansicoloring or timeout ones do add extra complexity (blocks) to pipeline scripts, making them much harder to write in a clean way.

          Also they have the bad habit of not downgrading gracefully if one of these optional plugins are not available.

          If we would be able to use some kind of annotation mechanism to enable them when they are available it would much easier for everyone.

          ssbarnea Sorin Sbarnea added a comment - I am really interested about this subject because all these wrappers like: timestamper, ansicoloring or timeout ones do add extra complexity (blocks) to pipeline scripts, making them much harder to write in a clean way. Also they have the bad habit of not downgrading gracefully if one of these optional plugins are not available. If we would be able to use some kind of annotation mechanism to enable them when they are available it would much easier for everyone.

          No, I haven't seen any examples. I'm not even sure if this is something pipeline supports?

          stevengbrown Steven G Brown added a comment - No, I haven't seen any examples. I'm not even sure if this is something pipeline supports?

          So we don't have an example still?

          quas Jakub Pawlinski added a comment - So we don't have an example still?

          Glad you like the new syntax. I don't know off the top of my head how your example code would look, but let me know if you work it out!

          stevengbrown Steven G Brown added a comment - Glad you like the new syntax. I don't know off the top of my head how your example code would look, but let me know if you work it out!

          People

            Unassigned Unassigned
            ssbarnea Sorin Sbarnea
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: