Quantcast

Declarative pipelines vs scripted

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Declarative pipelines vs scripted

Nick Le Mouton
Hi,

I'm just getting my head around pipeline as code and have converted my previous Jenkins job/ant build targets to a Jenkinsfile. As I was looking for documentation on the Jenkins site, I'm seeing mentions of declarative pipelines and it differs from what I've written.

Which method should I be looking to use (especially with blue ocean)? Declarative or scripted? Why should I be using one over the other?

Can I also get some feedback on my Jenkinsfile (https://gist.github.com/NoodlesNZ/bf9b50cab82093097796d354e37083f0)? It's hard to find examples beyond "hello world"/simple pipelines.

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e61441d9-e358-4429-b1bc-98f244b0dad5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Declarative pipelines vs scripted

Bill Dennis
Hi -

I'm tending to use Declarative as my preference after starting with the scripted like you did. I'm finding:

  • With declarative can have more of the job configuration in the Jenkinsfile like parameters and SCM polling. It means the Jenkins server can pick up the Jenkinsfiles for projects automatically with a MultiBranch pipeline container or GH Organisation. So you don't have to create the jobs configs, just add the Jenkinsfile in the repo with the code.

  • I really like the post section handling in Declarative for handling errors and failures. You can have post handing at the job or stage level. It means you don't need the try-catch-finally handling that you have. Seems cleaner to me.

  • Declaration and use of tools is cleaner. Also setup of environment variables for the build.
I don't see any issues with your scripted pipeline. I would use the "error('Some failure occurred')" step instead of throwing / re-throwing exceptions for errors, It allows to generate the error message at the point the failure occurs. I do google searches against github looking for interesting Jenkinsfiles or look in the CloudBees / Jenkins repos there.

I can recommend looking at the Declarative pipeline!

--Bill



On Friday, 17 March 2017 03:55:48 UTC, Nick Le Mouton wrote:
Hi,

I'm just getting my head around pipeline as code and have converted my previous Jenkins job/ant build targets to a Jenkinsfile. As I was looking for documentation on the Jenkins site, I'm seeing mentions of declarative pipelines and it differs from what I've written.

Which method should I be looking to use (especially with blue ocean)? Declarative or scripted? Why should I be using one over the other?

Can I also get some feedback on my Jenkinsfile (<a href="https://gist.github.com/NoodlesNZ/bf9b50cab82093097796d354e37083f0" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2FNoodlesNZ%2Fbf9b50cab82093097796d354e37083f0\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE3Ese3luyZSAnoSFA9c-HJyArw2A&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2FNoodlesNZ%2Fbf9b50cab82093097796d354e37083f0\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE3Ese3luyZSAnoSFA9c-HJyArw2A&#39;;return true;">https://gist.github.com/NoodlesNZ/bf9b50cab82093097796d354e37083f0)? It's hard to find examples beyond "hello world"/simple pipelines.

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/5bb89e53-6b98-458e-a406-8870b75feb03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Declarative pipelines vs scripted

stephenconnolly
Go declarative.

The latest blue ocean RC includes a visual editor for declarative

The only reason to use scripted is if you have some particularly complex task to achieve... and that is typically a bad smell anyway.

On Fri 17 Mar 2017 at 11:38, Bill Dennis <[hidden email]> wrote:
Hi -

I'm tending to use Declarative as my preference after starting with the scripted like you did. I'm finding:

  • With declarative can have more of the job configuration in the Jenkinsfile like parameters and SCM polling. It means the Jenkins server can pick up the Jenkinsfiles for projects automatically with a MultiBranch pipeline container or GH Organisation. So you don't have to create the jobs configs, just add the Jenkinsfile in the repo with the code.

  • I really like the post section handling in Declarative for handling errors and failures. You can have post handing at the job or stage level. It means you don't need the try-catch-finally handling that you have. Seems cleaner to me.

  • Declaration and use of tools is cleaner. Also setup of environment variables for the build.
I don't see any issues with your scripted pipeline. I would use the "error('Some failure occurred')" step instead of throwing / re-throwing exceptions for errors, It allows to generate the error message at the point the failure occurs. I do google searches against github looking for interesting Jenkinsfiles or look in the CloudBees / Jenkins repos there.

I can recommend looking at the Declarative pipeline!

--Bill



On Friday, 17 March 2017 03:55:48 UTC, Nick Le Mouton wrote:
Hi,

I'm just getting my head around pipeline as code and have converted my previous Jenkins job/ant build targets to a Jenkinsfile. As I was looking for documentation on the Jenkins site, I'm seeing mentions of declarative pipelines and it differs from what I've written.

Which method should I be looking to use (especially with blue ocean)? Declarative or scripted? Why should I be using one over the other?

Can I also get some feedback on my Jenkinsfile (https://gist.github.com/NoodlesNZ/bf9b50cab82093097796d354e37083f0)? It's hard to find examples beyond "hello world"/simple pipelines.

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/5bb89e53-6b98-458e-a406-8870b75feb03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CA%2BnPnMz%2BZ95CvN-NifMy_XUApi2A2ek7C9N9o-v3mudZpsShrw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Declarative pipelines vs scripted

Nick Le Mouton
Thanks to both of you. I've started converting my pipelines over to declarative. Bill, you're right, the post section seems a lot nicer than the hacky try-catch-finally.

Nick

On Saturday, March 18, 2017 at 12:56:42 AM UTC+13, Stephen Connolly wrote:
Go declarative.

The latest blue ocean RC includes a visual editor for declarative

The only reason to use scripted is if you have some particularly complex task to achieve... and that is typically a bad smell anyway.

On Fri 17 Mar 2017 at 11:38, Bill Dennis <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="-M-EV0QzBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">bill....@...> wrote:
Hi -

I'm tending to use Declarative as my preference after starting with the scripted like you did. I'm finding:

  • With declarative can have more of the job configuration in the Jenkinsfile like parameters and SCM polling. It means the Jenkins server can pick up the Jenkinsfiles for projects automatically with a MultiBranch pipeline container or GH Organisation. So you don't have to create the jobs configs, just add the Jenkinsfile in the repo with the code.

  • I really like the post section handling in Declarative for handling errors and failures. You can have post handing at the job or stage level. It means you don't need the try-catch-finally handling that you have. Seems cleaner to me.

  • Declaration and use of tools is cleaner. Also setup of environment variables for the build.
I don't see any issues with your scripted pipeline. I would use the "error('Some failure occurred')" step instead of throwing / re-throwing exceptions for errors, It allows to generate the error message at the point the failure occurs. I do google searches against github looking for interesting Jenkinsfiles or look in the CloudBees / Jenkins repos there.

I can recommend looking at the Declarative pipeline!

--Bill



On Friday, 17 March 2017 03:55:48 UTC, Nick Le Mouton wrote:
Hi,

I'm just getting my head around pipeline as code and have converted my previous Jenkins job/ant build targets to a Jenkinsfile. As I was looking for documentation on the Jenkins site, I'm seeing mentions of declarative pipelines and it differs from what I've written.

Which method should I be looking to use (especially with blue ocean)? Declarative or scripted? Why should I be using one over the other?

Can I also get some feedback on my Jenkinsfile (<a href="https://gist.github.com/NoodlesNZ/bf9b50cab82093097796d354e37083f0" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2FNoodlesNZ%2Fbf9b50cab82093097796d354e37083f0\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE3Ese3luyZSAnoSFA9c-HJyArw2A&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2FNoodlesNZ%2Fbf9b50cab82093097796d354e37083f0\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE3Ese3luyZSAnoSFA9c-HJyArw2A&#39;;return true;">https://gist.github.com/NoodlesNZ/bf9b50cab82093097796d354e37083f0)? It's hard to find examples beyond "hello world"/simple pipelines.

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="-M-EV0QzBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/5bb89e53-6b98-458e-a406-8870b75feb03%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/5bb89e53-6b98-458e-a406-8870b75feb03%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/5bb89e53-6b98-458e-a406-8870b75feb03%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/5bb89e53-6b98-458e-a406-8870b75feb03%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.
--
Sent from my phone

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ac1c97f8-e407-4803-9185-b54fd7c5997e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Declarative pipelines vs scripted

Cuong Tran
In reply to this post by Nick Le Mouton
The declarative option is nice but you will lose the ability to extract out reusable code via the shared library.  For example, you can't do this yet:

MyCompanyStandardPipeline {
    ... // which will plugin standard sections...
}

On Thursday, March 16, 2017 at 8:55:48 PM UTC-7, Nick Le Mouton wrote:
Hi,

I'm just getting my head around pipeline as code and have converted my previous Jenkins job/ant build targets to a Jenkinsfile. As I was looking for documentation on the Jenkins site, I'm seeing mentions of declarative pipelines and it differs from what I've written.

Which method should I be looking to use (especially with blue ocean)? Declarative or scripted? Why should I be using one over the other?

Can I also get some feedback on my Jenkinsfile (<a href="https://gist.github.com/NoodlesNZ/bf9b50cab82093097796d354e37083f0" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2FNoodlesNZ%2Fbf9b50cab82093097796d354e37083f0\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE3Ese3luyZSAnoSFA9c-HJyArw2A&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2FNoodlesNZ%2Fbf9b50cab82093097796d354e37083f0\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE3Ese3luyZSAnoSFA9c-HJyArw2A&#39;;return true;">https://gist.github.com/NoodlesNZ/bf9b50cab82093097796d354e37083f0)? It's hard to find examples beyond "hello world"/simple pipelines.

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fdd17e1a-35fa-41b2-bd16-e5c136a456f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...