Skip to content

Instantly share code, notes, and snippets.

@beatngu13
Last active April 16, 2021 22:35
Show Gist options
  • Save beatngu13/113eed1f208c3199a3aeae979b408fd1 to your computer and use it in GitHub Desktop.
Save beatngu13/113eed1f208c3199a3aeae979b408fd1 to your computer and use it in GitHub Desktop.
Cron-triggered Jenkins pipeline to send patches via email on available Maven dependency updates
pipeline {
agent any
triggers {
cron('00 23 * * 1-5')
}
stages {
stage('Check dependency updates') {
steps {
script {
String filename = 'dependency-updates.patch'
String script = """
mvn versions:use-latest-versions -B -U -DgenerateBackupPoms=false
git diff --unified=0 --exit-code pom.xml > ${filename}
"""
int exitCode = sh script: script, returnStatus: true
if (exitCode == 1) {
emailext subject: 'Dependency updates available',
body: "See attached patch: ${filename}",
attachmentsPattern: "**/${filename}",
to: 'alice@example.com, bob@example.com'
}
}
}
}
}
}
@beatngu13
Copy link
Author

The Maven Version Plugin is a beast! Also check out its other goals such as versions:update-properties to update your properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment