New simpler pipeline

Adding basic script to generate combinations of builds in python.
Probably can use some existing script for this, but this was simpler to
get working with pipeline.

Pipeline to query the python script for build configuration names,
obtain parameters for them, then trigger downstream jobs for them. Does
not yet run any LAVA tests.

Also putting build commands into this repository instead of just being
in the job. This makes it far easier to reproduce what would be run in
Jenkins.

Change-Id: Ie1a7431eb38191e7fcd23edebd284537878e2dde
Signed-off-by: Dean Birch <dean.birch@arm.com>
diff --git a/jenkins/verify.py b/jenkins/verify.py
new file mode 100755
index 0000000..11c8eed
--- /dev/null
+++ b/jenkins/verify.py
@@ -0,0 +1,140 @@
+#!/usr/bin/env python3
+"""
+Posts a verification to Gerrit verify-status plugin.
+"""
+
+__copyright__ = """
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+ """
+
+import argparse
+import json
+import os
+import sys
+import requests
+
+
+def check_plugins(base_url, auth):
+    """
+    Checks if the verify-status plugin is installed
+    """
+    plugin_url = "{}/a/plugins/".format(base_url)
+    headers = {"Content-Type": "application/json; charset=UTF-8"}
+    try:
+        request = requests.get(plugin_url, auth=auth, headers=headers)
+    except requests.exceptions.RequestException as exception:
+        print("Error checking plugins: {}".format(str(exception)), file=sys.stderr)
+        sys.exit(1)
+    if request.status_code != 200:
+        print("Could not check if verify-status plugin is installed")
+        return
+    json_plugins = json.loads(request.text.replace(")]}'",""))
+    if "verify-status" not in json_plugins:
+        print("verify-status plugin not installed.")
+        sys.exit(0)
+
+
+def submit_verification(base_url, auth, changeset, patchset_revision, verify_details):
+    """
+    Handles the actual post request.
+    """
+    check_plugins(base_url, auth)
+    post_data = {
+        "verifications": {
+            verify_details["verify_name"]: {
+                "url": verify_details["job_url"],
+                "value": verify_details["value"],
+                "abstain": verify_details["abstain"],
+                "reporter": verify_details["reporter"],
+                "comment": verify_details["comment"],
+                "category": verify_details["category"],
+                "duration": verify_details["duration"],
+            }
+        }
+    }
+    submit_url = "{}/a/changes/{}/revisions/{}/verify-status~verifications".format(
+        base_url, changeset, patchset_revision
+    )
+    headers = {"Content-Type": "application/json; charset=UTF-8"}
+    post = None
+    try:
+        post = requests.post(
+            submit_url, data=json.dumps(post_data), auth=auth, headers=headers,
+        )
+    except requests.exceptions.RequestException as exception:
+        print("Error posting to verify-status:", file=sys.stderr)
+        print(str(exception), file=sys.stderr)
+        sys.exit(1)
+    if post.status_code == 204:
+        print("Gerrit verify-status posted successfully.")
+    else:
+        print(
+            "Error posting to verify-status: {}".format(post.status_code),
+            file=sys.stderr,
+        )
+        print(post.text, file=sys.stderr)
+        sys.exit(1)
+
+
+if __name__ == "__main__":
+    PARSER = argparse.ArgumentParser(
+        description="Submits a job verification to verify-status plugin of Gerrit"
+    )
+    PARSER.add_argument("--host", help="Gerrit Host", default=os.getenv("GERRIT_HOST"))
+    PARSER.add_argument("--job-url", help="Job URL.", default=os.getenv("BUILD_URL"))
+    PARSER.add_argument("--value", help="Verification value.")
+    PARSER.add_argument(
+        "--changeset",
+        help="Changeset in Gerrit to verify.",
+        default=os.getenv("GERRIT_CHANGE_NUMBER"),
+    )
+    PARSER.add_argument(
+        "--patchset-revision",
+        help="Commit SHA of revision in Gerrit to verify.",
+        default=os.getenv("GERRIT_PATCHSET_REVISION"),
+    )
+    PARSER.add_argument(
+        "--verify-name", help="Name to give the job verifcation message."
+    )
+    PARSER.add_argument(
+        "--user", help="Username to authenticate as.", default=os.getenv("VERIFY_USER")
+    )
+    PARSER.add_argument(
+        "--password",
+        help="Password or token to authenticate as. "
+        "Defaults to VERIFY_PASSWORD environment variable.",
+        default=os.getenv("VERIFY_PASSWORD"),
+    )
+    PARSER.add_argument(
+        "--abstain",
+        help="Whether this should affect the final voting value.",
+        action="store_true",
+    )
+    PARSER.add_argument("--reporter", help="Metadata for reporter.", default="")
+    PARSER.add_argument("--comment", help="Metadata for comment.", default="")
+    PARSER.add_argument("--category", help="Metadata for category.", default="")
+    PARSER.add_argument("--duration", help="Duration of the job.", default="")
+    PARSER.add_argument("--protocol", help="Protocol to use.", default="https")
+    PARSER.add_argument("--port", help="Port to use.", default=None)
+    ARGS = PARSER.parse_args()
+    submit_verification(
+        "{}://{}{}".format(ARGS.protocol, ARGS.host, ":{}".format(ARGS.port) if ARGS.port else ""),
+        (ARGS.user, ARGS.password),
+        ARGS.changeset,
+        ARGS.patchset_revision,
+        {
+            "verify_name": ARGS.verify_name,
+            "job_url": ARGS.job_url,
+            "value": int(ARGS.value),
+            "abstain": bool(ARGS.abstain),
+            "reporter": ARGS.reporter,
+            "comment": ARGS.comment,
+            "category": ARGS.category,
+            "duration": ARGS.duration,
+        },
+    )