Plugin development : extension to add custom options in declarative pipeline

49 views
Skip to first unread message

Bill Dennis

unread,
May 17, 2018, 12:44:36 PM5/17/18
to Jenkins Developers
I am developing a Jenkins pipeline plugin that provides some custom block scoped steps something like this:

withFoo( fooParams ) {
   
// Some code block that uses the declared "Foo" thing
}


My withFoo step creates some object "Foo" that is made available in the code block to my other custom steps.

I have all this sort of thing working with custom block-scoped steps and simple steps and it is going well in my declarative pipelines and providing the functionality I need.

However the "foo" is only available in a pipeline code block in a single declarative stage and it won't be available in a post handler unless I re-declare it ( think).

I am envisioning some scenarios where I want my "Foo" object to be available to the whole job in the pipeline context using something like "options" (or possibly at the stage options level).

So I am looking at the possibility of some custom option like this:

pipeline {

 agent none

 options
{
     
// Declare the Foo
     foo
(fooParams)
 
}


 
// Rest of pipeline uses the Foo in stages or post sections
}

To give some context, the "Foo" is some sort of connection to a remote system so it could be expensive to keep tearing it down and re-establishing it.

Is there a way to provide custom options like this to have an object is created and put in the pipeline context for the whole pipeline and can be consumed by my other custom steps?

I had a look at the existing Jenkins extension point documents and around some plugins in GitHub but I cannot tell whether these options are generally extendable in this way.

Thanks for any suggestions or pointers anyone here may have!

--Bill

Robert Sandell

unread,
May 18, 2018, 5:37:15 AM5/18/18
to jenkin...@googlegroups.com
I think

 options {
     
// Declare the Foo

     withFoo
(fooParams)
 
}

Should work as is. Have you tried it?

/B

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/92d6270f-7da0-4aea-b7ba-5f41eb1be190%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Robert Sandell
Software Engineer
CloudBees, Inc.
CloudBees-Logo.png
Twitter: robert_sandell

Bill Dennis

unread,
Jun 7, 2018, 11:52:51 AM6/7/18
to Jenkins Developers
Robert - 

Thank you very much for your suggestion, this did work.

I did not appreciate that a block-scoped Jenkins pipeline step can be used in the options section like this and it is a very cool feature.

My only problem now is I want my custom step used options to be able to take credentials (user , password) from a credentials declared in the environment section, but env variables don't seem to be usable in the options. I think I need a credentials ID param to the step to make this work nicely.

Thanks again!
Bill
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages