Plugin development : extension to add custom options in declarative pipeline

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Plugin development : extension to add custom options in declarative pipeline

Bill Dennis
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

--
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: Plugin development : extension to add custom options in declarative pipeline

Robert Sandell-2
I think

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

Should work as is. Have you tried it?

/B

2018-05-17 18:44 GMT+02:00 Bill Dennis <[hidden email]>:
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

--
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 [hidden email].
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CALzHZS1%3DRT1DujCDuu6H1PtbCpaCEPY%2BeaXL7%3DbeKeVaPybaiQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Plugin development : extension to add custom options in declarative pipeline

Bill Dennis
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

On Friday, 18 May 2018 10:37:15 UTC+1, Robert Sandell wrote:
I think

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

Should work as is. Have you tried it?

/B

2018-05-17 18:44 GMT+02:00 Bill Dennis <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="2oWFnyGzCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">bill....@...>:
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

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="2oWFnyGzCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-dev/92d6270f-7da0-4aea-b7ba-5f41eb1be190%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/92d6270f-7da0-4aea-b7ba-5f41eb1be190%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/92d6270f-7da0-4aea-b7ba-5f41eb1be190%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-dev/92d6270f-7da0-4aea-b7ba-5f41eb1be190%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.



--
Robert Sandell
Software Engineer
CloudBees,<a href="http:///" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http:///&#39;;return true;" onclick="this.href=&#39;http:///&#39;;return true;"> Inc.
<a href="http://www.cloudbees.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.cloudbees.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFD5q8pAuc6CUBHDK6LlPC4hQt3lQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.cloudbees.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFD5q8pAuc6CUBHDK6LlPC4hQt3lQ&#39;;return true;">CloudBees-Logo.png
E: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="2oWFnyGzCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rsan...@...
Twitter: robert_sandell

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/c7e4b0ba-6e27-4707-92fb-54290fef0c92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.