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, but I am not sure how that can be done.
I also referred
this answer 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, It seems EnvVars are not available to SimpleBuildStep, but then how that can be achieved in similarly simple way?