2

I have a Jenkins job with:

  • Git SCM which refreshes a local workspace.
  • A shell script which also runs some Git CLI commands to make some assertions, and build a dynamic recipients.txt file for ext-email to send-to.
  • Email Ext to send messages, which are supposed to be only on successful refresh of the workspace, then based on some failed assertion based on Git commands in a test in the shell script. This is currently triggered with Failure - Any.

What I would like to do is avoid the specific failure email in the case of a remote Git outage causing a Git command to abort - it should only mail-out if all Git commands succeed, but then detect a certain condition.

Is there a way to abort the build and not send Email Ext messages in the case when Git commands fail due to issues on the remote? Would it be best to try and work out how to abort the build and email when Git fails, or is there some Email Ext trigger which could avoid that?

javabrett
  • 7,020
  • 4
  • 51
  • 73

1 Answers1

1

If I understand the core of the problem you just don't want an error triggered if Git CLI commands fail. You could execute your git shell commands within a try/catch block. That should prevent a non-zero error code and thus no email will be sent.

sh """
    {
        git clonep https://...
        # oops, typo above would normally exit 1 (error)
    } || {
        echo Continuing
    }
"""
Fo.
  • 3,752
  • 7
  • 28
  • 44
  • This is great for the 2nd set of Git processes, the ones in the shell-block. I'm now looking for how email-ext can be forced to ignore a failure in the built-in Git SCM block also. If that fails, the script block won't execute, but `Email was triggered for: Failure - Any` will still occur. That is, I don't know how to try/catch the workspace SCM block. – javabrett Nov 25 '16 at 18:15
  • I added some detail to the question - I am building a dynamic recipients list as `recipients.txt`. I find that if I add a https://wiki.jenkins-ci.org/display/JENKINS/pre-scm-buildstep I can ensure that this file is always cleared-up even before the Git SCM plugin runs, thereby ensuring that I don't get a failure email under those conditions. – javabrett Nov 25 '16 at 18:28