ding

Using DING with Jenkins

Jenkins is the long-standing self-hosted CI server. DING’s ding run wraps a pipeline step, evaluates rules during execution, and fires alerts on exit — automatically tagging each alert with the Jenkins job name and build number.

Prerequisites

Minimal example

Declarative Jenkinsfile:

pipeline {
    agent any
    stages {
        stage('Install DING') {
            steps {
                sh '''
                    curl -sSL https://github.com/ding-labs/ding/releases/latest/download/ding_linux_amd64.tar.gz | tar -xz
                '''
            }
        }
        stage('Test') {
            steps {
                withCredentials([string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL')]) {
                    sh './ding run --config ding.yaml -- ./run-tests.sh'
                }
            }
        }
    }
}

ding.yaml:

notifiers:
  slack:
    type: slack
    url: ${SLACK_WEBHOOK_URL}

rules:
  - name: ci_job_failed
    match:
      metric: run.exit
    condition: value > 0
    message: " build  failed (exit  after )"
    alert:
      - notifier: slack

Add the Slack webhook as a secret text credential named slack-webhook.

What you get

A Slack message when the build exits non-zero, tagged with the Jenkins job name and build number. Successful builds produce no notification.

Configuration

runctx auto-detects Jenkins via the presence of JENKINS_URL and captures these labels:

Label Jenkins env var
run_id BUILD_TAG
runner "jenkins" (set by runctx)
job JOB_NAME
build BUILD_NUMBER

Note: Jenkins doesn’t expose repo, branch, or commit as universal env vars (those depend on which SCM plugin is in use). To capture them, add explicit env vars in your Jenkinsfile from the SCM step’s metadata. See Configuration for the full notifier reference.

Verification

  1. Locally: ding validate --config ding.yaml — confirms the rule parses.
  2. Trigger the job. Confirm a successful build produces no alert.
  3. Force a failure (exit 1 in run-tests.sh). Confirm the alert fires in Slack within ~5 seconds of build exit.

If the alert doesn’t fire, check the Jenkins build console for ding output. Common issues: webhook credential not exposed to the job (withCredentials block missing or wrong credentialsId), or drain_timeout shorter than the notifier retry window — see Configuration → drain_timeout.

Tradeoffs / known limitations

Escalation criteria

This recipe is a Tier-2 candidate by the program’s standard rubric:

Tier-2 candidate. The “no SCM-aware labels” friction is the structural problem — every Jenkins user wants branch and commit in their alerts, and the recipe leaves that as homework. A Jenkins plugin (ding-jenkins-plugin) that pulls SCM metadata into runctx labels would collapse this. Defer until 2+ users ask.