2

I wrote a gradle task run some process for an android project. This task will be executed in a jenkins job. I would like to set the build status of the jenkins job based on the status of the process i run. Below is a simple snippet from the task.

class MyTask extends DefaultTask {

    @TaskAction
    public void runDirectTask() {

        PluginConfig config = project.mytask

        TASK_STATUS status =myProcessWithStatusAsReturn(config)

        switch (status) {
            case PASS:
                println("status pass") //TODO handle build pass
                break
            case UNSTABLE:
                println("status unstable") //TODO handle build unstable
                break
            case FAILED:
                println("status fail") //TODO handle build fail
                break
        }
    }
}

Thanks in advance..

Thilek
  • 676
  • 6
  • 18

1 Answers1

0

I;ve had the same problem. In Groovy it turns out to be pretty simple:

manager.build.@result = hudson.model.Result.NEW-STATUS-TO-SET

see this question (How to mark a build unstable in Jenkins when running shell scripts) for more discussion. The main problem I had was that this didn't work with an old version of Jenkins/Groovy plugins; when I tried on the latest version it worked like a charm.

I'm not sure for gradle, but I think that you should look for the manager stuff.

Community
  • 1
  • 1
Davide Vernizzi
  • 1,327
  • 17
  • 25