Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know the Jenkins Build Status

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!

like image 345
JuanCarlosFR Avatar asked Oct 29 '25 15:10

JuanCarlosFR


1 Answers

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

like image 143
psalvi21 Avatar answered Oct 31 '25 12:10

psalvi21



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!