SimpleBuildStep return value?

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

SimpleBuildStep return value?

Michael Carter
SimpleBuildStep when I use it in pipeline how do I get it to feed back something?

eg:

def myValue = mySimpleBuildStepCmd

--
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/0a7c8744-d0e1-40a5-8bfd-0a18910235bbn%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: SimpleBuildStep return value?

Ulli Hafner
I don’t think that this is possible, you need to write a Step. (Or your SimpleBuildStep creates an action that you can read after the step call.)

Am 25.08.2020 um 23:41 schrieb Michael Carter <[hidden email]>:

SimpleBuildStep when I use it in pipeline how do I get it to feed back something?

eg:

def myValue = mySimpleBuildStepCmd

--
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/0a7c8744-d0e1-40a5-8bfd-0a18910235bbn%40googlegroups.com.

--
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/141918A8-22C5-4E41-9303-D72E25D7FF24%40gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: SimpleBuildStep return value?

Michael Carter
I write the output to a file so, reading the json output from the file is my backup solution.   Really don't want to repeat code between pipeline/freestyle as my commands need both.

Next angle... any way to or example of an "out" variable?

eg: 

def value
myStep input: "something, output: value

On Wednesday, August 26, 2020 at 10:56:37 AM UTC-4 [hidden email] wrote:
I don’t think that this is possible, you need to write a Step. (Or your SimpleBuildStep creates an action that you can read after the step call.)

Am 25.08.2020 um 23:41 schrieb Michael Carter <[hidden email]>:

SimpleBuildStep when I use it in pipeline how do I get it to feed back something?

eg:

def myValue = mySimpleBuildStepCmd

--
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/0a7c8744-d0e1-40a5-8bfd-0a18910235bbn%40googlegroups.com.

--
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/fefc9cee-4d07-4537-99f6-78904d218b26n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: SimpleBuildStep return value?

Jesse Glick-4
On Wed, Aug 26, 2020 at 1:51 PM Michael Carter
<[hidden email]> wrote:
> Really don't want to repeat code between pipeline/freestyle as my commands need both.

Well, you cannot return values from `SimpleBuildStep` as that would
not work in freestyle, or for that matter in Declarative Pipeline. You
_can_ return values from an explicit `Step`, for use in Scripted
Pipeline, though you may want to consider alternate designs that do
not force scripting on the user. With no context it is impossible to
offer suggestions.

--
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/CANfRfr1mGLmV7CFVVme4gq%3D82H4oUPK9HXGMjCiR3UBgMKoPfg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: SimpleBuildStep return value?

Michael Carter
Use case.   I'm taking these REST enabled SQL engines we have and turning it into one command.   Mostly this would be used for datafixes so the large portion would enter the sql and just want to know what passed/failed.  Which I'm dumping the json output to a file and turning the results of the statements into junit file(s) which are reported up to the "Test Results" page.   This is about 90% of cases and will make those 1000+ users happy.

Then I've got the very few people that will select something and want to get at the data.  These users I'm dumping the json to a flat file.  So the freestyle users will just "cat <file> | jq ."  field sort of thing.   The pipeline scripted people will just "readJson" and be happy.

Then I've got two-three users who will insist on scripted pipeline and use the fact they have to use two commands not one as a reason to scrap the entire jenkins project.

So at this stage just trying to eliminate that second "readJson" call without having to write a "step" with identical code for both freestyle and pipeline.  If it's not possible... I'll just have to engage these people in a fight when it comes up.

On Wednesday, August 26, 2020 at 4:56:33 PM UTC-4 Jesse Glick wrote:
On Wed, Aug 26, 2020 at 1:51 PM Michael Carter
<[hidden email]> wrote:
> Really don't want to repeat code between pipeline/freestyle as my commands need both.

Well, you cannot return values from `SimpleBuildStep` as that would
not work in freestyle, or for that matter in Declarative Pipeline. You
_can_ return values from an explicit `Step`, for use in Scripted
Pipeline, though you may want to consider alternate designs that do
not force scripting on the user. With no context it is impossible to
offer suggestions.

--
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/4ec5b755-2c2e-479a-80f4-ed752d28dd78n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: SimpleBuildStep return value?

Jesse Glick-4
On Thu, Aug 27, 2020 at 8:58 AM Michael Carter
<[hidden email]> wrote:
> [For a few] users I'm dumping the json to a flat file.  So the freestyle users will just "cat <file> | jq ."  field sort of thing.   The pipeline scripted people will just "readJson" and be happy.

If the freestyle users can do what they need using the likes of `jq`,
then the Pipeline users can do the same in a `sh` step, right? The
only reason to load data into the Pipeline script (i.e., manipulate in
Groovy) is if it must be used as the input to some other step or
conditional, for which `readJson` suffices—or you can use
`returnStdout` on some call to `jq -r` and not even need that step.

> insist on scripted pipeline [yet] have to use two commands not one

You can always supply Groovy libraries which offer various
conveniences and idioms while keeping the actual `Step`s simple.

--
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/CANfRfr0q_hUAzLbk_xVvX-sscfJT_4%3DFt8SwZcErSKktTYOJ4Q%40mail.gmail.com.