You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins能否在作业配置(含参数、脚本等)变更时发送通知邮件?

How to Set Up Automated Notifications for Jenkins Job Configuration Changes

Absolutely! Jenkins totally supports sending automated notifications whenever someone modifies a job's configuration—whether it's updating string/choice parameters, editing shell scripts, or tweaking any other job settings. Here’s the lowdown on the most reliable methods to get this working:

1. Go with the Job Configuration History + Email Extension Plugin Combo

This is the go-to approach for most teams because it’s straightforward and requires minimal custom code. Here’s how to implement it:

  • First, install both the Job Configuration History Plugin and Email Extension Plugin via Jenkins’ Plugin Manager. Just search for them and hit install.
  • Head to Manage Jenkins > Configure System to set things up:
    • Scroll to the Job Configuration History section and check the box to "Notify on configuration changes". You can even tweak filters here if you only want alerts for specific types of changes (like parameter edits vs. script updates).
    • Next, jump to the Extended E-mail Notification section to configure your SMTP server details, default recipient list, and email templates. Use built-in variables to make the emails useful:
      • ${CHANGES}: Shows a diff of exactly what was modified
      • ${USER}: The account that made the change
      • ${JOB_NAME}: Name of the updated job
      • For a direct link to the job’s config, you can use ${JOB_URL}configure instead of the standard build URL.
  • Test it out by making a small change to a test job—you should get an email with all the relevant details right away.

2. Custom Pipeline Script for Granular Control

If you need more flexibility (like only sending alerts when specific parts of a config are changed), a Jenkins Pipeline script is your friend. Here’s a simplified example to get you started:

pipeline {
    agent any
    triggers {
        // Poll every hour for config changes (adjust schedule as needed)
        pollSCM('H * * * *')
    }
    stages {
        stage('Check for Config Updates') {
            steps {
                script {
                    // Path to store the last known config state
                    def lastConfigPath = "${WORKSPACE}/last_job_config.xml"
                    def currentConfig = readFile("${JOB_CONFIG}/config.xml")
                    
                    // Compare current config to the saved version
                    if (fileExists(lastConfigPath)) {
                        def lastConfig = readFile(lastConfigPath)
                        if (currentConfig != lastConfig) {
                            // Send notification email
                            emailext(
                                to: 'your-team@example.com',
                                subject: "🚨 Jenkins Job Updated: ${JOB_NAME}",
                                body: """
                                    Hi team,
                                    ${USER} just modified the configuration for job: ${JOB_NAME}
                                    Changes made:
                                    ${CHANGES}
                                    View job config: ${JOB_URL}configure
                                """
                            )
                            // Update the saved config to the current version
                            writeFile(file: lastConfigPath, text: currentConfig)
                        }
                    } else {
                        // Save initial config if it's the first run
                        writeFile(file: lastConfigPath, text: currentConfig)
                    }
                }
            }
        }
    }
}

Note: This method requires storing the previous config version (either on the Jenkins server or in your repo) to compare against the current state. Adjust the polling schedule and email content to fit your team’s needs.

3. Audit Trail Plugin for Full Jenkins-Wide Monitoring

If you want to track all Jenkins actions (not just job config changes), the Audit Trail Plugin is a solid choice. It logs every user action, and you can configure it to send emails specifically when job configurations are updated. This is great if you need a centralized audit log plus notifications for all system changes.


Pro tip: Always test your setup with a non-critical job first to make sure notifications are triggering correctly and include all the info your team needs. And don’t forget to limit recipients to only relevant folks to avoid cluttering inboxes!

内容的提问来源于stack exchange,提问作者Kim Kimo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:24:09