Search code examples
jenkinscompiler-errorshudsonbuild-server

How to check the Console Output for a specific string and raise an error on the Build?


I have Hudson configured for building a project.

And the console output, after building is, as follows:

Compiling ./main.py ...
Sorry: IndentationError: ('expected an indented block', ('./main.py', 8, 6, 'thread.start_new_thread( foo.FooThread, () )\n'))
Compiling ./udpReceiver.py ...
<<<<< build finished!
POST BUILD TASK : SUCCESS
END OF POST BUILD TASK : 0

Deleting project workspace... 
done

Finished: SUCCESS

As you can see, I have an Indentation Error....and Hudson says that the build job finished with success.

What I want is something like this:

Check if the string "IndentationError" is presented on the console output text ... if so, than the build should be: Finished: FAILED!!!!!!!!

How can I accomplish this?


Solution

  • I confirm that the Log Parser plugin can do the job to change the build status to failure.

    Install the plugin and create a rule set for your Python build for example:

    enter image description here

    In the create the /var/lib/jenkins/logParserRules/python-error file:

    error /IndentationError/
    

    Next, update the Python build with these settings:

    enter image description here

    The build status will be changed to FAILURE:

    Compiling ./udpReceiver.py ...'
    Sorry: IndentationError: ('expected an indented block', ('./main.py', 8, 6, 'thread.start_new_thread( foo.FooThread, () )\n'))
    Compiling ./udpReceiver.py ...
    Build step 'Console output (build log) parsing' changed build result to FAILURE