Declarative pipelines vs scripted

7,643 views
Skip to first unread message

Nick Le Mouton

unread,
Mar 16, 2017, 11:55:48 PM3/16/17
to Jenkins Users
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

Bill Dennis

unread,
Mar 17, 2017, 7:38:51 AM3/17/17
to Jenkins Users
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

Stephen Connolly

unread,
Mar 17, 2017, 7:56:42 AM3/17/17
to jenkins...@googlegroups.com
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.

--
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 jenkinsci-use...@googlegroups.com.
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

Nick Le Mouton

unread,
Mar 19, 2017, 5:36:28 PM3/19/17
to Jenkins Users
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

Cuong Tran

unread,
Mar 21, 2017, 10:56:09 PM3/21/17
to Jenkins Users
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...

Baptiste Mathus

unread,
Mar 28, 2017, 4:45:52 PM3/28/17
to jenkins...@googlegroups.com
Well, yes, you can use Shared Libraries with Declarative. Example: https://jenkins.io/blog/2017/02/15/declarative-notifications/

--
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 jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fdd17e1a-35fa-41b2-bd16-e5c136a456f8%40googlegroups.com.

Valerie Fernandes

unread,
Nov 21, 2017, 1:41:58 AM11/21/17
to Jenkins Users
Hi Guys,

Are you aware of anything else lined up(other than the editor) that will only support declarative in the future? 
Reason I ask is, we already have some "scripted" pipelines. Maybe we need to consider rewriting them if Jenkins road-map indicates a shift towards declarative. 
Also if my pipeline is "Declarative" can it use an existing shared library that is "scripted"?

On Wednesday, 29 March 2017 02:15:52 UTC+5:30, Baptiste Mathus wrote:
Well, yes, you can use Shared Libraries with Declarative. Example: https://jenkins.io/blog/2017/02/15/declarative-notifications/
2017-03-22 3:56 GMT+01:00 Cuong Tran <cuong...@gmail.com>:
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 (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 jenkinsci-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages