Plugin Pipeline Environment Variables

95 views
Skip to first unread message

David Brooks

unread,
Mar 27, 2017, 9:47:10 AM3/27/17
to Jenkins Developers
Hey all,

I have been working on an internal plugin for our company and currently having it working for Freestyle projects. However, I would like to update it to support Pipelines and have a question about Environment Variables. I implemented SimpleBuildStep, but according to a fellow dev (here) we cannot get env variables using SimpleBuildStep. I was instructed to implement Step instead, which according to that same developer, would provide env vars. However, I do not see any documentation around Step and BuildStep has been deprecated. I just need a little nudge in the right direction, not the full solution.  Currently, the header of our class looks like: 
public class IntrepidBuilder extends Builder implements SimpleBuildStep {

Additionally, if anyone has any experience using a plugin hosted in a private repo on GitHub, how would I provide our Jenkins instance with the correct credentials to checkout the plugin from our private repo?

Thanks,
David

Daniel Beck

unread,
Mar 27, 2017, 9:50:59 AM3/27/17
to jenkin...@googlegroups.com

> On 27.03.2017, at 15:47, David Brooks <dbr...@intrepid.io> wrote:
>
> However, I do not see any documentation around Step and BuildStep has been deprecated. I just need a little nudge in the right direction, not the full solution.

I think https://github.com/jenkinsci/workflow-step-api-plugin/blob/master/README.md is what you're looking for. `step` is not provided by core.

David Brooks

unread,
Mar 27, 2017, 10:44:32 AM3/27/17
to Jenkins Developers, m...@beckweb.net
Thanks Daniel, I will take a crack at it!

David Brooks

unread,
Mar 27, 2017, 11:58:41 AM3/27/17
to Jenkins Developers, m...@beckweb.net
So I extended Step, and was able to get my run() method to print out text in a pipeline project. However, my plugin no longer appears in a Freestyle project under Build Steps because I am not extending Builder nor implementing SimpleBuildStep anymore. Do you think that I can have this plugin working under both project types just using Step?


On Monday, March 27, 2017 at 9:50:59 AM UTC-4, Daniel Beck wrote:

Robert St. John

unread,
Mar 29, 2017, 11:22:12 AM3/29/17
to Jenkins Developers, m...@beckweb.net
David, you can take a look at what I did in the android-signing plugin.  I used @StepContextParameter to inject EnvVars into the pipeline step (SignApksStep), which then forwards the values to the SimpleBuildStep/Builder instance.  Hopefully that helps and meets your needs.

Robert

Jesse Glick

unread,
Mar 29, 2017, 2:41:03 PM3/29/17
to Jenkins Dev
On Mon, Mar 27, 2017 at 11:58 AM, David Brooks <dbr...@intrepid.io> wrote:
> my plugin no longer appears in a Freestyle
> project under Build Steps because I am not extending Builder nor
> implementing SimpleBuildStep anymore. Do you think that I can have this
> plugin working under both project types just using Step?

No, `Step` is a Pipeline API. The API for making one extension appear
in both freestyle and Pipeline jobs is `SimpleBuildStep`. If you
cannot use that API, then you must have both a `Builder` and a `Step`,
presumably both delegating to a common utility class for the bulk of
the implementation.

Dzmitry Kashlach

unread,
Apr 3, 2017, 3:33:09 AM4/3/17
to Jenkins Developers
Hi David,

I had exactly the same problem(it seems to me).
Try to follow this discussion, it can be useful.

David Brooks

unread,
Apr 3, 2017, 1:26:38 PM4/3/17
to Jenkins Developers
Hey everyone,

Thanks for the help! I have gone the route of implementing `Step` directly. All seems to be working just fine! I have taken a route closer to what Jesse described above.

Thanks,
David
Reply all
Reply to author
Forward
0 new messages