Hi, 
I am completely new to Jenkins plugin development, and have no prior 
experience with this.

I have a post-build action, which I am trying to support in pipeline. 

My class heading reads like this:

> public class GetDataNotifier extends Notifier implements SimpleBuildStep {
> ...


I also have:

> @Override
> public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, 
> @Nonnull Launcher launcher, @Nonnull TaskListener taskListener) throws 
> InterruptedException, IOException {
> ...


In this perform method, I need to do this:
Check build result, and if it is successful, read a user defined env var 
named PACKAGE_ID and use it to make some external API call. 

To read the build result, I am trying this:

> Result r = run.getResult();
> String result = r.toString();
> taskListener.getLogger().println("Build Result = " + result);


And, to get that PACKAGE_ID, I am trying this:

> EnvVars envVars = run.getEnvironment(listener);
> packageId = envVars.get("PACKAGE_ID", "");
> taskListener.getLogger().println("PACKAGE_ID read from EnvVars is " + 
> packageId);


My pipeline script is like this:

> pipeline {
>      environment { 
>         PACKAGE_ID = 'coming_from_environment'
>     }
>     
>     agent any
>     stages {
>         stage('Example') {
>             steps {
>                 echo 'Hello World'
>             }
>         }
>     }
>     post { 
>         always { 
>             echo 'in post build stage'
>             step([$class: 'GetDataNotifier', apiPass: 'password', 
> apiServer: 'https://api.example.com', apiUser: 'user'])
>         }
>     }
> }


However, I get neither Result r (its found to be null always), nor the env 
var PACKAGE_ID - it is never found. 
How can I that PACKAGE_ID at least? 

I have came across this link 
<https://github.com/jenkinsci/workflow-step-api-plugin#creating-an-asynchronous-step>,
 
but I am not sure how that can be done. 
I also referred this answer 
<https://groups.google.com/forum/#!msg/jenkinsci-dev/7rcEhU-8mC4/My_Fa_nPAgAJ> 
on another message in this group, but I still have no clue how I can get 
Step class that works with pipeline and what all things I need to do for 
that. 
According to this ticket 
<https://issues.jenkins-ci.org/browse/JENKINS-29144>, It seems EnvVars are 
not available to SimpleBuildStep, but then how that can be achieved in 
similarly simple way?

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/5fceec96-8056-4e1e-ac72-e9d527f9b372%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to