osmith submitted this change.

View Change

Approvals: laforge: Looks good to me, but someone else must approve pespin: Looks good to me, approved Jenkins Builder: Verified
jobs/gerrit-verifications: post comment on start

Post a link to gerrit when starting the build that contains the link to
the pipeline, without sending mail notifications.

This is useful when a gerrit verification build takes rather long, and
it's not clear if a build for gerrit verification was actually started
or not. Also I find this useful when debugging the CI scripts.

Change-Id: I75c5b8874f606739ff557ff0711bb9449a2b4259
---
M jobs/gerrit-verifications-comment.yml
M jobs/gerrit-verifications.yml
M scripts/jenkins-gerrit/comment_generate.py
M scripts/jenkins-gerrit/comment_send.sh
4 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/jobs/gerrit-verifications-comment.yml b/jobs/gerrit-verifications-comment.yml
index 1c672b9..f781bf8 100644
--- a/jobs/gerrit-verifications-comment.yml
+++ b/jobs/gerrit-verifications-comment.yml
@@ -1,5 +1,6 @@
-# This job runs at the end of the pipeline in gerrit-verififactions.yml, to
-# post a list of failed/successful job links to gerrit and to vote +V/-V.
+# This job runs at the start/end of the pipeline in gerrit-verifications.yml.
+# On start it posts a link to the pipeline to gerrit, and on end a list of
+# failed/successful job links together with a vote +V/-V.

- project:
name: gerrit-verifications-comment
@@ -18,7 +19,7 @@
artifact-days-to-keep: -1
artifact-num-to-keep: -1
description: |
- Result job of CI for patches sent to <a href="https://gerrit.osmocom.org">gerrit</a>.
+ Send start and result comments to <a href="https://gerrit.osmocom.org">gerrit</a>.
</br></br>
Related issue: <a href="https://osmocom.org/issues/2385">OS#2385</a>

@@ -29,6 +30,9 @@
osmo-ci.git branch
default: 'master'
- string:
+ name: COMMENT_TYPE
+ description: set by gerrit verification pipeline job
+ - string:
name: GERRIT_PROJECT
description: set by gerrit verification pipeline job
- string:
diff --git a/jobs/gerrit-verifications.yml b/jobs/gerrit-verifications.yml
index 1896a98..b83b5aa 100644
--- a/jobs/gerrit-verifications.yml
+++ b/jobs/gerrit-verifications.yml
@@ -416,6 +416,29 @@
stages {{
stage("Verification") {{
parallel {{
+ stage("Start Comment") {{
+ steps {{
+ // Run the comment job to add the pipeline link to gerrit
+ script {{
+ // Keep going on failure
+ catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {{
+ build job: 'gerrit-verifications-comment', parameters: [
+ string(name: "COMMENT_TYPE", value: "start"),
+ string(name: "GERRIT_PROJECT", value: "${{env.GERRIT_PROJECT}}"),
+ string(name: "GERRIT_CHANGE_NUMBER", value: "${{env.GERRIT_CHANGE_NUMBER}}"),
+ string(name: "GERRIT_PATCHSET_NUMBER", value: "${{env.GERRIT_PATCHSET_NUMBER}}"),
+ 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}}"),
+ ]
+ }}
+ }}
+ }}
+ }}
stage("Build") {{
when {{
expression {{ params.PIPELINE_BUILD }}
@@ -512,6 +535,7 @@
// comment + vote to gerrit
script {{
build job: 'gerrit-verifications-comment', parameters: [
+ string(name: "COMMENT_TYPE", value: "result"),
string(name: "GERRIT_PROJECT", value: "${{env.GERRIT_PROJECT}}"),
string(name: "GERRIT_CHANGE_NUMBER", value: "${{env.GERRIT_CHANGE_NUMBER}}"),
string(name: "GERRIT_PATCHSET_NUMBER", value: "${{env.GERRIT_PATCHSET_NUMBER}}"),
diff --git a/scripts/jenkins-gerrit/comment_generate.py b/scripts/jenkins-gerrit/comment_generate.py
index d4937c0..dc69f8f 100755
--- a/scripts/jenkins-gerrit/comment_generate.py
+++ b/scripts/jenkins-gerrit/comment_generate.py
@@ -15,12 +15,16 @@

def parse_args():
parser = argparse.ArgumentParser(
- description="Get a summary of failed / successful builds from the CI"
- " pipeline we run for patches submitted to gerrit.")
+ description="Prepare a comment to be submitted to gerrit. Depending on"
+ " the comment type, (start) either a link to the pipeline,"
+ " or (result) a summary of failed / successful builds from"
+ " the pipeline we run for patches submitted to gerrit.")
parser.add_argument("build_url",
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("-t", "--type", help="comment type",
+ choices=["start", "result"], required=True)
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")
@@ -153,7 +157,7 @@
return ret


-def get_pipeline_summary(build_url, notify_on_success):
+def get_comment_result(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",
@@ -211,17 +215,26 @@
"notify": notify}


+def get_comment_start(build_url):
+ return {"tag": "jenkins",
+ "message": f"Build Started\n{build_url}consoleFull",
+ "notify": "NONE"}
+
+
def main():
args = parse_args()
- summary = get_pipeline_summary(args.build_url, args.notify_on_success)
+ if args.type == "result":
+ comment = get_comment_result(args.build_url, args.notify_on_success)
+ else:
+ comment = get_comment_start(args.build_url)

print()
- print(summary["message"])
- print(f"notify: {summary['notify']}")
+ print(comment["message"])
+ print(f"notify: {comment['notify']}")

if args.output:
with open(args.output, "w") as handle:
- json.dump(summary, handle, indent=4)
+ json.dump(comment, handle, indent=4)

if __name__ == "__main__":
main()
diff --git a/scripts/jenkins-gerrit/comment_send.sh b/scripts/jenkins-gerrit/comment_send.sh
index bd7b81d..24fec27 100755
--- a/scripts/jenkins-gerrit/comment_send.sh
+++ b/scripts/jenkins-gerrit/comment_send.sh
@@ -18,6 +18,7 @@

./comment_generate.py "$PIPELINE_BUILD_URL" \
-o gerrit_report.json \
+ -t "$COMMENT_TYPE" \
$arg_notify

ssh \

To view, visit change 30988. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: I75c5b8874f606739ff557ff0711bb9449a2b4259
Gerrit-Change-Number: 30988
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-MessageType: merged