How can a plugin save output when running in pipeline

79 views
Skip to first unread message

Christian McHugh

unread,
Nov 3, 2016, 7:31:07 PM11/3/16
to Jenkins Developers
Does anyone have a recommendation or example for how to save output of a plugin into a variable when running as a pipeline job? 

Currently, the saltstack plugin uses listener.getLogger().println() to display output. However this is not to be saved to a variable. 
def saltoutput = salt arguments: 'ls -la', authtype: 'pam', clientInterface: local(blockbuild: false, jobPollTime: 5, target: 'master', targetType: 'glob'), credentialsId: 'a3d814c2-84ed-4752-94a8-271791bb5375', function: 'cmd.run', kwarguments: 'runas=jenkins', servername: 'http://localhost:8000'
// output displayed in the build console here, even though it should have been saved into variable

echo ("Salt outputted ${saltoutput}")       // this creates "Salt outputted null"  


Thanks!

Jesse Glick

unread,
Nov 7, 2016, 3:45:22 PM11/7/16
to Jenkins Dev
On Thu, Nov 3, 2016 at 7:31 PM, Christian McHugh
<christia...@gmail.com> wrote:
> Does anyone have a recommendation or example for how to save output of a
> plugin into a variable when running as a pipeline job?

`PwdStep` shows the simplest example I can think of.

Christian McHugh

unread,
Dec 6, 2016, 1:26:20 AM12/6/16
to jenkin...@googlegroups.com
Hey Jesse,

I've been fiddling with this off and on, but I'm not making any progress.

Can you advice on how to get https://github.com/jenkinsci/saltstack-plugin/blob/master/src/main/java/com/waytta/SaltAPIBuilder.java#L217 this  returnArray.toString() variable exported in a pipeline job? 


Thanks much!


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/ZnPA7zW6UFY/unsubscribe.
To unsubscribe from this group and all its topics, 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/CANfRfr3qKWeC8VwctvH3eMfAyi7YApodVTfaP8_Kv5za0LrSxg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Jesse Glick

unread,
Dec 6, 2016, 11:28:08 AM12/6/16
to Jenkins Dev
On Tue, Dec 6, 2016 at 1:26 AM, Christian McHugh
<christia...@gmail.com> wrote:
> Can you advice on how to get
> https://github.com/jenkinsci/saltstack-plugin/blob/master/src/main/java/com/waytta/SaltAPIBuilder.java#L217
> this returnArray.toString() variable exported in a pipeline job?

You can return a value from a `Step`. Not a `SimpleBuildStep`.

Christian McHugh

unread,
Dec 26, 2016, 4:13:56 PM12/26/16
to jenkin...@googlegroups.com
Hey everyone/Jesse,

Thanks for all of your assistance and pointers thus far!

In the currently released pre-pipeline version, this plugin was capable of performing its own variable substitution to read in existing environment variables as well as export the return into an envvar for further processing. With the groovy enabled pipeline syntax, these over complicated devices can be done away with. Reading in envvars is no longer necessary as any processing can be handled outside of the plugin in groovy, and once the plugin is able to return the API output, the hack of exporting a variable will be unnecessary as well. 

I'm a bit stuck on the conversion of SimpleBuildStep to full step needed to have the pipeline syntax be able to return output to be saved into a variable.
As I'm not a jenkins framework expert by any means, would anyone be able to provide any additional assistance on the mentioned step conversion?
The master branch of https://github.com/jenkinsci/saltstack-plugin/commits/master has been cleaned up a little bit which should help readability a tad.

Again, thanks much. Any help you can provide would be appreciated.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/ZnPA7zW6UFY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.

Jesse Glick

unread,
Jan 5, 2017, 4:44:19 PM1/5/17
to Jenkins Dev
On Mon, Dec 26, 2016 at 4:13 PM, Christian McHugh
<christia...@gmail.com> wrote:
> I'm a bit stuck on the conversion of SimpleBuildStep to full step needed to
> have the pipeline syntax be able to return output to be saved into a
> variable.
> As I'm not a jenkins framework expert by any means, would anyone be able to
> provide any additional assistance on the mentioned step conversion?

Does https://github.com/jenkinsci/workflow-basic-steps-plugin/blob/32c7e74953c98acb2703f4130b48cd93dabcf65f/src/main/java/org/jenkinsci/plugins/workflow/steps/ReadFileStep.java#L40-L105
help?

https://github.com/jenkinsci/workflow-step-api-plugin/blob/master/README.md#creating-a-basic-synchronous-step
Reply all
Reply to author
Forward
0 new messages