Add get-credentials groovy script to lftools 53/11553/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Tue, 26 Jun 2018 00:50:27 +0000 (20:50 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Tue, 26 Jun 2018 00:50:31 +0000 (20:50 -0400)
This migrates the script in global-jjb into lftools as a command.

https://github.com/lfit/releng-global-jjb/blob/v0.21.4/jenkins-admin/get_all_creds.groovy

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

index 698ec13..83ef71d 100644 (file)
@@ -36,6 +36,32 @@ def jenkins_cli(ctx, server, user, password):
         password=password)
 
 
+@click.command()
+@click.pass_context
+def get_credentials(ctx):
+    """Print all available Credentials."""
+    server = ctx.obj['server']
+    groovy_script = """
+import com.cloudbees.plugins.credentials.*
+
+println "Printing all the credentials and passwords..."
+def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
+    com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class,
+    Jenkins.instance,
+    null,
+    null
+);
+
+for (c in creds) {
+    try {
+        println(c.id + " : " + c.password )
+    } catch (MissingPropertyException) {}
+}
+"""
+    result = server.run_script(groovy_script)
+    print(result)
+
+
 @click.command()
 @click.argument('groovy_file')
 @click.pass_context
@@ -71,5 +97,6 @@ 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(get_credentials, name='get-credentials')
 jenkins_cli.add_command(groovy)
 jenkins_cli.add_command(quiet_down, name='quiet-down')