From b40969d8fafaed6effef0afc593949b2d3164fc5 Mon Sep 17 00:00:00 2001 From: nhyatt Date: Fri, 12 Apr 2024 07:00:41 -0500 Subject: [PATCH] adds bitwarden version notification --- notify-bitwarden.jenkins | 137 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 notify-bitwarden.jenkins diff --git a/notify-bitwarden.jenkins b/notify-bitwarden.jenkins new file mode 100644 index 0000000..ecf5a3f --- /dev/null +++ b/notify-bitwarden.jenkins @@ -0,0 +1,137 @@ +def repository = "registry.c.test-chamber-13.lan" +def label = "kubernetes-${UUID.randomUUID().toString()}" +def templateName = "pipeline-worker" + +def mailBody +// def bitwardenReleases +def bitwardenInstalled +def bitwardenLatestServer +def bitwardenLatestRelease + +pipeline { + + agent { + kubernetes { + yaml functions.podYaml( + repo: repository, + templateName: templateName, + alpine: true, + ) + } + } + + stages { + stage ('Initalize Jenkins') { + steps { + script { + workspace = pwd() + } + } + } + + stage ('Get latest Tag') { + steps { + container ('alpine') { + script { + sh """ + if ! command -v curl &> /dev/null; then + apk add --no-cache curl + fi + if ! command -v jq &> /dev/null; then + apk add --no-cache jq + fi + """ + /* + bitwardenReleases = sh ( + script: """ + curl \ + --location \ + --silent \ + --fail \ + --request GET \ + --url https://api.github.com/repos/bitwarden/server/releases/latest | \ + jq -r 'select(.prerelease == false) | .tag_name[1:]' + """, + returnStdout: true + ).trim() + */ + bitwardenInstalled = sh ( + script: """ + curl \ + --location \ + --silent \ + --fail \ + --request GET \ + --url "https://bitwarden.smoothnet.org/admin/home/getinstalledwebversion" | \ + sed -e 's/"//g' + """, + returnStdout: true + ).trim() + bitwardenLatestServer = sh ( + script: """ + curl \ + --location \ + --silent \ + --fail \ + --request GET \ + --url "https://bitwarden.smoothnet.org/admin/home/getlatestversion?project=Core" | \ + sed -e 's/"//g' + """, + returnStdout: true + ).trim() + bitwardenLatestWeb = sh ( + script: """ + curl \ + --location \ + --silent \ + --fail \ + --request GET \ + --url "https://bitwarden.smoothnet.org/admin/home/getlatestversion?project=Web" | \ + sed -e 's/"//g' + """, + returnStdout: true + ).trim() + } + } + } + } + + if (bitwardenInstalled != bitwardenLatestServer || bitwardenInstalled != bitwardenLatestWeb) { + stage ("Send Mail") { + steps { + script { + mailBody = """Dear Bitwarden Admin, +A new version of bitwarden was released: + Server: v${bitwardenLatestServer} + Web: v${bitwardenLatestWeb} +Currently installed version: v${bitwardenInstalled} + +Please login to bitwarden-admin to check for updates. +Bitwarden Admin + https://bitwarden.smoothnet.org/admin +Docker Containers + admin: https://hub.docker.com/r/bitwarden/admin/tags + api: https://hub.docker.com/r/bitwarden/api/tags + attachments: https://hub.docker.com/r/bitwarden/attachments/tags + icons: https://hub.docker.com/r/bitwarden/icons/tags + identity: https://hub.docker.com/r/bitwarden/notifications/tags + notifications: https://hub.docker.com/r/bitwarden/notifications/tags + web: https://hub.docker.com/r/bitwarden/web/tags +""" + + echo mailBody + emailext( + body: mailBody, + mimeType: 'text/plain', + replyTo: '${DEFAULT_REPLYTO}', + subject: '${DEFAULT_SUBJECT}', + to: "nhyatt@smoothnet.org", + ) + } + } + } + } else { + println "Bitwarden is up to date!" + } + } +}