Best Practices for Pipeline Global Function Args (Maps vs Closures)

47 views
Skip to first unread message

Kenneth Baltrinic

unread,
Sep 19, 2016, 8:30:46 AM9/19/16
to Jenkins Users
Trying to get my head around what is the best way to implement some custom pipeline DLS commands using global functions. I am looking at the examples given under Defining a more structured DSL, which shows an example of accepting arguments via variable assignments inside of a closure.  Is this the preferred method?  It seems most build in commands (git, sh, etc) accept a Map of arguments.  I am not a groovy expert but am trying to understand why/when one approach is better than the other?  Any thoughts or illumination on this would be appreciated.

Cuong Tran

unread,
Sep 19, 2016, 3:13:40 PM9/19/16
to Jenkins Users
I'd stick with map arguments for simple cases.  Even the example from the wiki is simpler if you use map.  

Move to the closure option once you have more experience or complex usage.  For example, the new (simplified) syntax for pipleline can be implemented as closure:

pipeline {
  stages {
    ...
  }

  postBuild {

Daniel

unread,
Dec 30, 2016, 9:40:17 AM12/30/16
to Jenkins Users
Hi Kenneth, I am curious, have you found a satisfying answer yet?

I am currently splitting up our build pipeline into reusable global methods and am asking myself the same questions.

I played around with the standardBuild example to implement a build skeleton for our build pipelines:

But more and more I come to the conclusion, that I will avoid using the closure technique and just implement a global function with proper arguments.

Maybe there should be some guidelines (and maybe a real world example) added to the best practises when to use which technique.

Regards and a happy new year,
Daniel
Reply all
Reply to author
Forward
0 new messages