Add a groovy command to lftools 33/8433/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Thu, 18 Jan 2018 22:03:01 +0000 (17:03 -0500)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Thu, 18 Jan 2018 22:03:12 +0000 (17:03 -0500)
Using python-jenkins' run_groovy API to allow us to execute
groovy scripts from lftools.

Change-Id: If5afb69b738a0cee6ee653b5d70ba9b5dac67fd0
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
lftools/cli/jenkins/__init__.py

index 5487b41..f9cbf4d 100644 (file)
@@ -36,6 +36,18 @@ def jenkins_cli(ctx, server, user, password):
         password=password)
 
 
+@click.command()
+@click.argument('groovy_file')
+@click.pass_context
+def groovy(ctx, groovy_file):
+    """Run a groovy script."""
+    with open(groovy_file, 'r') as f:
+        data = f.read()
+
+    server = ctx.obj['server']
+    server.run_script(data)
+
+
 @click.command()
 @click.option("-n/-y", is_flag=True, prompt="Quiet down Jenkins?", required=True)
 @click.pass_context
@@ -58,4 +70,5 @@ def quiet_down(ctx, n):
 jenkins_cli.add_command(plugins_init, name='plugins')
 jenkins_cli.add_command(nodes)
 jenkins_cli.add_command(builds)
+jenkins_cli.add_command(groovy)
 jenkins_cli.add_command(quiet_down, name='quiet-down')