InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Jenkis

  • Install Jenkins on Linux
  • Clone a project
  • Setup build failure email
  • Setup build cron
  • Shell - how to continue on error
  • Delete old builds
 
  • Home
  • > Tutorials
  • > CI
  • > Jenkins

Jenkins – how to setup build failure email

By admin on Jan 22, 2016

Getting email of a build failure is a common use case in Jenkins. We would want to get notified whenever any build fails and when it is back to success. Here are steps to setup email on build failure in Jenkins. This tutorial requires Jenkins setup on Ubuntu Linux with a py.test project and publish junit reports post build action.

  1. First create a test python test case which always fails. Create test_fail.py with following content.
    #!/usr/bin/python
    import pytest
    
    def test_fail1():
      assert 1 == 2, "This is expected to fail"

    If you run py.test test_fail.py you should get output similar to this:

    =============================================================== test session starts ================================================================
    platform linux2 -- Python 2.7.6, pytest-2.8.2, py-1.4.30, pluggy-0.3.1
    rootdir: /path_to_tests/tests, inifile: 
    collected 1 items 
    
    test_fail.py F
    
    ===================================================================== FAILURES =====================================================================
    ____________________________________________________________________ test_fail1 ____________________________________________________________________
    
        def test_fail1():
    >     assert 1 == 2, "This is expected to fail"
    E     AssertionError: This is expected to fail
    E     assert 1 == 2
    
    test_fail.py:5: AssertionError
    
  2. Create a test py.test test project and name it test_fail (refer to Jenkins setup tutorial).
  3. In project settings, click post build email notification action as shown below:
    jenkins-post-build-email-notification
  4. Enter one or more emails (separated by space) as shown below and select send email on every unstable build. Click on Save.
    jenkins-email-notification-form
  5. Change project build command to:

    py.test --junitxml=result.xml test_fail.py
    

    jenkins-test-project-settings-build-commant-for-test-fail

  6. Setup Jenkins from email if not done already. Go to Manage Jenkins > Configure System. Then in section “Jenkins Location” enter a suitable system admin email. Notifications will come from this email address.
    jenkins-manage-configure-from-email
  7. Now run the build for the project manually and you should get a failure email which will look something like:

    Subject: Build failed in Jenkins: test_fail #2
    See 
    
    ------------------------------------------
    Started by user anonymous
    Building in workspace 
    Updating http://svnserver.com/path_to_tests/tests at revision '2016-01-20T05:17:12.947 +0000'
    At revision 4801
    no change for http://svnserver.com/path_to_tests/tests since the previous build
    ...
    ...
    

Suggested posts:

  1. Python selenium – print browser log (including javascript errors) with phantomjs
  2. Bash – variables in double quotes vs without quotes
  3. How to setup MailChimp email list
  4. PHP – preg_replace back reference (in replacement text) examples
  5. How to setup Google feedburner email subscription newsletter
  6. Google feedburner email subscription vs Mailchimp
  7. HTML attribute contenteditable – make an element editable
  8. Selenium Phantomjs – check browser errors using pytest
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged CI, Jenkins, Linux, Tutorials, Ubuntu Linux
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress