Im actually doing my own Jenkins plugin, and I have a class that extends from RunListener<Run>, with the next onCompleted() method:
@Override
public void onCompleted(Run build, TaskListener listener) {
int number = build.number;
EnvVars env;
String name = "";
try {
env = build.getEnvironment(listener);
name = env.get("JOB_NAME") + "-" + env.get("BUILD_NUMBER");
} catch (IOException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
GraphicAction act = new GraphicAction(name);
build.getActions().add((Action) act);
}
Is there any posibility of executing the last 2 lines only if the build has been successful?
Thanks!
You can use Jenkins REST API to get the job status: {JENKINS_URL}/job/{JOB_NAME}/lastBuild/api/json
and then look for value for "status".
jenkins rest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With