Hi Victor, 

Thanks for the tip. 

My issue is that the step does not return a map or any value. I am 
referring to the  "step" metastep. Unlike the "checkout" metastep that 
returns a map (see  https://issues.jenkins.io/browse/JENKINS-26100), step 
does not return a value. For instance, this is not possible  or even it is 
possible, I don't know how I can send back the data from MyStepClass

def vars = step ([$class: "MyStepClass"...] 

But the following is possible because the checkout metastep can get back a 
map if MySCMClass overrides #buildEnvironment

def vars = checkout ([$class: "MySCMClass"...]   

I am trying to figure out if I can make "MyStepClass" return a map somehow. 
The workaround is to contribute an action that in turn exports the 
name-value pairs to the build environment. I can then access it in the 
script using the env object.

On Thursday, November 12, 2020 at 4:11:32 PM UTC+5:30 
[email protected] wrote:

> Hey,
>
> You can use the groovy.transform.Field with a global variable in the 
> pipeline, for instance, the below snippet set the value of myStep in the 
> variable myStepData which it's consumed later on in another stage
>
>
> import groovy.transform.Field
> @Field def myStepData = [:]
>
> pipeline {
>     ...
>     stage('producer') {
>         ...
>         steps {
>             script {
>                // myStep returns a map with values
>                myStepData = myStep(....)
>                ...
>             }
>          }
>      }
>      ....
>     stage('consumer') {
>         ...
>         steps {
>             script {
>                // where <field> is one of the entries
>                if (myStepData?.<field>?.equals('acme'))) {
>           
>                }
>             }
>          }
>      }
> }
>
> Cheers
> On Thursday, 12 November 2020 at 05:08:37 UTC Lakshmi Narasimhan wrote:
>
>> Hello Jenkins devs,
>>
>> Is it possible to get back a return value from a pipeline step? I am 
>> looking for a map similar to  checkout step 
>> https://issues.jenkins.io/browse/JENKINS-26100.
>>
>> Currently, I am exporting the values I need to get back from the step to 
>> the environment using an EnvironmentContributingAction.
>>
>> Thanks in advance for your help.
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/1ded9bc0-5a11-45a5-b256-41559a008322n%40googlegroups.com.

Reply via email to