mirror of https://gerrit.osmocom.org/osmo-ci
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: I75c5b8874f606739ff557ff0711bb9449a2b4259changes/88/30988/2
parent
ed604a0bb3
commit
9f1889a494
|
@ -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>
|
||||
|
||||
|
@ -28,6 +29,9 @@
|
|||
description: |
|
||||
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
|
||||
|
|
|
@ -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}}"),
|
||||
|
|
|
@ -15,12 +15,16 @@ re_job_type = re.compile("JOB_TYPE=([a-zA-Z-_0-9]*),")
|
|||
|
||||
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 @@ def get_jobs_list_str(jobs):
|
|||
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 @@ def get_pipeline_summary(build_url, notify_on_success):
|
|||
"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()
|
||||
|
|
|
@ -18,6 +18,7 @@ set -x
|
|||
|
||||
./comment_generate.py "$PIPELINE_BUILD_URL" \
|
||||
-o gerrit_report.json \
|
||||
-t "$COMMENT_TYPE" \
|
||||
$arg_notify
|
||||
|
||||
ssh \
|
||||
|
|
Loading…
Reference in New Issue