aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2022-10-27 16:29:39 +0200
committerOliver Smith <osmith@sysmocom.de>2022-10-27 16:43:14 +0200
commitc4df55dcfd81e6adb4585e8cb51bc8b1fd4bdbf7 (patch)
treea52f918f7229062ac4e8aecc1a67d3c0ec861bda
parentf52c26a695edf456dce65bf24235c3a3382a891f (diff)
jenkins-gerrit: send mail for V+1 for some usersosmith/gerrit-mail-on-success
Add a list of users that do not only get a notification mail when the gerrit verification failed, but also on success. Change-Id: I603b8a911c8f17aa726d9e3d5d644ad3262b42dd
-rw-r--r--jobs/gerrit-pipeline-result.yml3
-rw-r--r--jobs/gerrit-verifications.yml1
-rwxr-xr-xscripts/jenkins-gerrit/pipeline_summary.py11
-rwxr-xr-xscripts/jenkins-gerrit/pipeline_summary_send.sh22
4 files changed, 32 insertions, 5 deletions
diff --git a/jobs/gerrit-pipeline-result.yml b/jobs/gerrit-pipeline-result.yml
index ac54cee..c3c03b6 100644
--- a/jobs/gerrit-pipeline-result.yml
+++ b/jobs/gerrit-pipeline-result.yml
@@ -38,6 +38,9 @@
name: GERRIT_PATCHSET_REVISION
description: set by gerrit verification pipeline job
- string:
+ name: GERRIT_PATCHSET_UPLOADER_NAME
+ description: set by gerrit verification pipeline job
+ - string:
name: GERRIT_PORT
description: set by gerrit verification pipeline job
- string:
diff --git a/jobs/gerrit-verifications.yml b/jobs/gerrit-verifications.yml
index a9616ff..9db1ebc 100644
--- a/jobs/gerrit-verifications.yml
+++ b/jobs/gerrit-verifications.yml
@@ -484,6 +484,7 @@
string(name: "GERRIT_BRANCH", value: "${{env.GERRIT_BRANCH}}"),
string(name: "GERRIT_HOST", value: "${{env.GERRIT_HOST}}"),
string(name: "GERRIT_PATCHSET_REVISION", value: "${{env.GERRIT_PATCHSET_REVISION}}"),
+ string(name: "GERRIT_PATCHSET_UPLOADER_NAME", value: "${{env.GERRIT_PATCHSET_UPLOADER_NAME}}"),
string(name: "GERRIT_PORT", value: "${{env.GERRIT_PORT}}"),
string(name: "GERRIT_REFSPEC", value: "${{env.GERRIT_REFSPEC}}"),
string(name: "PIPELINE_BUILD_URL", value: "${{env.BUILD_URL}}"),
diff --git a/scripts/jenkins-gerrit/pipeline_summary.py b/scripts/jenkins-gerrit/pipeline_summary.py
index 95ae821..44424d7 100755
--- a/scripts/jenkins-gerrit/pipeline_summary.py
+++ b/scripts/jenkins-gerrit/pipeline_summary.py
@@ -19,6 +19,9 @@ def parse_args():
help="$BUILD_URL of the pipeline job, e.g."
" https://jenkins.osmocom.org/jenkins/job/gerrit-osmo-bsc-nat/17/")
parser.add_argument("-o", "--output", help="output json file")
+ parser.add_argument("-n", "--notify-on-success", action="store_true",
+ help="always indicate in json that the owner should be"
+ " notified via mail, not only on failure")
return parser.parse_args()
@@ -132,7 +135,7 @@ def get_jobs_list_str(jobs):
return ret
-def get_pipeline_summary(build_url):
+def get_pipeline_summary(build_url, notify_on_success):
""" Generate a summary of failed and successful builds for gerrit.
:returns: a dict that is expected by gerrit's set-review api, e.g.
{"tag": "jenkins",
@@ -179,7 +182,7 @@ def get_pipeline_summary(build_url):
else:
summary += "Build Successful\n"
vote = 1
- notify = "NONE"
+ notify = "OWNER" if notify_on_success else "NONE"
# Reference:
# https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#set-review
@@ -192,9 +195,11 @@ def get_pipeline_summary(build_url):
def main():
args = parse_args()
- summary = get_pipeline_summary(args.build_url)
+ summary = get_pipeline_summary(args.build_url, args.notify_on_success)
+ print()
print(summary["message"])
+ print(f"notify: {summary['notify']}")
if args.output:
with open(args.output, "w") as handle:
diff --git a/scripts/jenkins-gerrit/pipeline_summary_send.sh b/scripts/jenkins-gerrit/pipeline_summary_send.sh
index d52ad9f..c49f428 100755
--- a/scripts/jenkins-gerrit/pipeline_summary_send.sh
+++ b/scripts/jenkins-gerrit/pipeline_summary_send.sh
@@ -1,6 +1,24 @@
-#!/bin/sh -ex
+#!/bin/sh -e
-./pipeline_summary.py "$PIPELINE_BUILD_URL" -o gerrit_report.json
+# By default, a mail notification will only be sent if the gerrit verification
+# failed. Add yourself here to also receive notifications on successs.
+notify_on_success_users="
+ pespin
+"
+
+arg_notify=""
+for i in $notify_on_success_users; do
+ if [ "$GERRIT_PATCHSET_UPLOADER_NAME" = "$i" ]; then
+ arg_notify="--notify-on-success"
+ break
+ fi
+done
+
+set -x
+
+./pipeline_summary.py "$PIPELINE_BUILD_URL" \
+ -o gerrit_report.json \
+ $arg_notify
ssh \
-p "$GERRIT_PORT" \