SimpleBuildStep return value?

32 views
Skip to first unread message

Michael Carter

unread,
Aug 25, 2020, 5:41:10 PM8/25/20
to Jenkins Developers
SimpleBuildStep when I use it in pipeline how do I get it to feed back something?

eg:

def myValue = mySimpleBuildStepCmd

Ullrich Hafner

unread,
Aug 26, 2020, 10:56:37 AM8/26/20
to Jenkins Developers
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.)

--
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-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/0a7c8744-d0e1-40a5-8bfd-0a18910235bbn%40googlegroups.com.

Michael Carter

unread,
Aug 26, 2020, 1:51:46 PM8/26/20
to Jenkins Developers
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

Jesse Glick

unread,
Aug 26, 2020, 4:56:33 PM8/26/20
to Jenkins Dev
On Wed, Aug 26, 2020 at 1:51 PM Michael Carter
<mikeyca...@gmail.com> 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.

Michael Carter

unread,
Aug 27, 2020, 8:57:54 AM8/27/20
to Jenkins Developers
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.

Jesse Glick

unread,
Aug 27, 2020, 1:47:50 PM8/27/20
to Jenkins Dev
On Thu, Aug 27, 2020 at 8:58 AM Michael Carter
<mikeyca...@gmail.com> 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.
Reply all
Reply to author
Forward
0 new messages