> Am 21.06.2021 um 00:52 schrieb long song <[email protected]>:
> 
> 
> Here is how I use the plugin the pipeline script
> 
>         steps {
>              script {
>                 def myResult = MyPlugin Parameter1: value1, Parameter2: value2
>                 println "$myResult"  
>              }
>          }
> 
> I expect to return a Json string or a map object which can contain running 
> status such as "repo: xxx, version: xxx, total incidents: xxx ..."
> 

Is your real requirement just to print out a structured text? Then use the 
Jenkins logger in your BuildStep. Then you don’t need a return value. 

> Are you talking about the interface hudson.tasks.BuildStep ?

No, this could be done with a  `org.jenkinsci.plugins.workflow.steps.Step`


> It returns a boolean but can't transport much infor. 
> 
> boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener 
> listener) throws InterruptedException, IOException;
> 
> To get the running result, I am thinking to store the running result as an 
> artifact and parse it out after running MyPlugin.
> 


This still looks too complicated. Use the Tell-Don't-Ask principle 
(https://martinfowler.com/bliki/TellDontAsk.html 
<https://martinfowler.com/bliki/TellDontAsk.html>)

Tell your Jenkins plugin what it should display and do not get values and work 
with these values. 


> Do you have some good practice that I can receive the running result from the 
> Jenkins Plugin ?
> 
> Thanks!
> 
> On Sun, Jun 20, 2021 at 6:24 AM Ullrich Hafner <[email protected] 
> <mailto:[email protected]>> wrote:
> It is possible to return values from a step (but not from a SimpleBuildStep) 
> 
> Before I go into details we need to make sure that this approach makes senes, 
> your requirements are not clear: 
> - What is in the value that you want to return? 
> - Why do you want to return a value? 
> - What do you want to do with the value?
> 
>> Am 19.06.2021 um 02:05 schrieb long song <[email protected] 
>> <mailto:[email protected]>>:
>> 
>> Hi,
>> 
>> Is there a way that I can receive a string value from running a Jenkins 
>> plugin in the Jenkins pipeline script ?
>> 
>> // the myResult is always null after running the Jenkins plugin "MyPlugin"
>> pipeline {
>>    agent any
>>    stages {
>>       stage('MyPlugin: MyPlugin Run') {
>>          steps {
>>              script {
>>                 def myResult = MyPlugin Parameter1: value1, Parameter2: 
>> value2
>>                 println "$myResult"  
>>              }
>>          }
>>       }
>>    }
>> 
>> Here is the MyPlugin implementation.
>> 
>> public class MyPluginBuilder extends Builder implements SimpleBuildStep {
>>      @Override
>>      public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath 
>> workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) 
>> throws IOException, InterruptedException { ... }
>> }
>> 
>> The return type of the method perform() is void.
>> 
>> By design, Jenkins doesn't want to return anything back.
>> 
>> To get the running result, I am thinking to store the running result as an 
>> artifact and parse it out after running MyPlugin.
>> 
>> Do you have some good practice that I can receive the running result from 
>> the Jenkins Plugin ?
>> 
>> Thanks !
>> Long
>> 
>> -- 
>> 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] 
>> <mailto:[email protected]>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jenkinsci-dev/CANDLextj0bbX4zwToHLYCFU4EuYMUQYd0r_6NxWNVszKToDVbw%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/jenkinsci-dev/CANDLextj0bbX4zwToHLYCFU4EuYMUQYd0r_6NxWNVszKToDVbw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> 
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jenkinsci-dev/DB6814A1-964E-40B2-B048-595D967EA10F%40gmail.com
>  
> <https://groups.google.com/d/msgid/jenkinsci-dev/DB6814A1-964E-40B2-B048-595D967EA10F%40gmail.com?utm_medium=email&utm_source=footer>.
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jenkinsci-dev/CANDLexvYg2nmA_0StJ_%2BCXBLDzyRE0NwNWCgcWGMPGnU4pPBzg%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/jenkinsci-dev/CANDLexvYg2nmA_0StJ_%2BCXBLDzyRE0NwNWCgcWGMPGnU4pPBzg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
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/4800A4E8-7B18-4685-A786-94F4180A7DDE%40gmail.com.

Reply via email to