[jenkins-ci PATCH 1/8] lcitool: Add "-r REVISION" argument for build

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This will allow users to build arbitrary branches from
arbitrary git repositories, but for the moment all it
does is parse the argument and pass it down to the
Ansible playbook.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 guests/lcitool | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index 2901a92..c12143d 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -351,8 +351,13 @@ class Application:
             metavar="PROJECTS",
             help="list of projects to consider",
         )
+        self._parser.add_argument(
+            "-r",
+            metavar="REVISION",
+            help="git revision to build (remote/branch)",
+        )
 
-    def _execute_playbook(self, playbook, hosts, projects):
+    def _execute_playbook(self, playbook, hosts, projects, revision):
         base = Util.get_base()
 
         flavor = self._config.get_flavor()
@@ -362,6 +367,14 @@ class Application:
         ansible_hosts = ",".join(self._inventory.expand_pattern(hosts))
         selected_projects = self._projects.expand_pattern(projects)
 
+        if revision is None:
+            raise Error("Missing git revision")
+        tokens = revision.split('/')
+        if len(tokens) < 2:
+            raise Error("Invalid git revision '{}'".format(revision))
+        git_remote = tokens[0]
+        git_branch = '/'.join(tokens[1:])
+
         ansible_cfg_path = os.path.join(base, "ansible.cfg")
         playbook_base = os.path.join(base, "playbooks", playbook)
         playbook_path = os.path.join(playbook_base, "main.yml")
@@ -372,6 +385,8 @@ class Application:
             "root_password_file": root_pass_file,
             "flavor": flavor,
             "selected_projects": selected_projects,
+            "git_remote": git_remote,
+            "git_branch": git_branch,
         })
 
         cmd = [
@@ -396,15 +411,15 @@ class Application:
         except Exception:
             raise Error("Failed to run {} on '{}'".format(playbook, hosts))
 
-    def _action_hosts(self, _hosts, _projects):
+    def _action_hosts(self, _hosts, _projects, _revision):
         for host in self._inventory.expand_pattern("all"):
             print(host)
 
-    def _action_projects(self, _hosts, _projects):
+    def _action_projects(self, _hosts, _projects, _revision):
         for project in self._projects.expand_pattern("all"):
             print(project)
 
-    def _action_install(self, hosts, _projects):
+    def _action_install(self, hosts, _projects, _revision):
         base = Util.get_base()
 
         flavor = self._config.get_flavor()
@@ -475,13 +490,13 @@ class Application:
             except Exception:
                 raise Error("Failed to install '{}'".format(host))
 
-    def _action_update(self, hosts, projects):
-        self._execute_playbook("update", hosts, projects)
+    def _action_update(self, hosts, projects, revision):
+        self._execute_playbook("update", hosts, projects, revision)
 
-    def _action_build(self, hosts, projects):
-        self._execute_playbook("build", hosts, projects)
+    def _action_build(self, hosts, projects, revision):
+        self._execute_playbook("build", hosts, projects, revision)
 
-    def _action_dockerfile(self, hosts, projects):
+    def _action_dockerfile(self, hosts, projects, _revision):
         mappings = self._projects.get_mappings()
 
         hosts = self._inventory.expand_pattern(hosts)
@@ -553,11 +568,12 @@ class Application:
         action = cmdline.a
         hosts = cmdline.h
         projects = cmdline.p
+        revision = cmdline.r
 
         method = "_action_{}".format(action.replace("-", "_"))
 
         if hasattr(self, method):
-            getattr(self, method).__call__(hosts, projects)
+            getattr(self, method).__call__(hosts, projects, revision)
         else:
             raise Error("Invalid action '{}'".format(action))
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux