← All guides

Guide · CI/CD

Monitor Jenkins with a dead man's switch

A Jenkins job can fail without Jenkins telling anyone: a trigger misfires, an agent goes offline, a webhook never arrives. A Mortemain check-in catches all of it, because it alerts on silence, not just on a red build.

1. Create a check

Create a check in Mortemain with the same period as your job's trigger (cron schedule, upstream job, or webhook), and a grace window wide enough to cover normal build-time variance. Copy its ping URL, it looks like https://ping.mortemain.com/your-check-uuid.

2. Ping on success, from a declarative pipeline

Add the check-in to the post block of your Jenkinsfile so it fires exactly when the pipeline finishes, in either direction:

 Jenkinsfile
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh './build.sh'
            }
        }
    }
    post {
        success {
            sh 'curl -fsS -m 10 https://ping.mortemain.com/your-check-uuid'
        }
        failure {
            sh 'curl -fsS -m 10 https://ping.mortemain.com/your-check-uuid/fail'
        }
    }
}

The /fail suffix triggers an alert immediately instead of waiting for the check-in to go missing, so a build that runs but exits non-zero is reported right away.

3. Track build duration (optional)

To measure how long each run takes, ping /start as the first step, before the real work begins:

 Jenkinsfile
stages {
    stage('Notify start') {
        steps {
            sh 'curl -fsS -m 10 https://ping.mortemain.com/your-check-uuid/start'
        }
    }
    stage('Build') {
        steps {
            sh './build.sh'
        }
    }
}

Mortemain then shows the elapsed time between the /start ping and the final check-in, so a build that suddenly takes twice as long shows up without a separate alert rule.

4. Freestyle jobs

No Jenkinsfile? Add a single Execute shell build step that wraps your existing command and pings on the way out, whichever way it goes:

 Execute shell
#!/bin/bash
curl -fsS -m 10 https://ping.mortemain.com/your-check-uuid/start

./build.sh
STATUS=$?

if [ $STATUS -eq 0 ]; then
  curl -fsS -m 10 https://ping.mortemain.com/your-check-uuid
else
  curl -fsS -m 10 https://ping.mortemain.com/your-check-uuid/fail
fi

exit $STATUS

Keeping the real exit code with exit $STATUS means Jenkins still marks the build red on failure, the check-in is only there to make sure someone is actually alerted.

Test it

Run the job once and confirm the check flips to up in Mortemain. Then make the build fail on purpose and watch the immediate alert from /fail arrive, and separately, disable the trigger for one cycle to confirm the missed-check-in alert fires after the grace window, that's the failure mode Jenkins won't tell you about on its own.