mirror of
https://github.com/Fishwaldo/rundeck-api-java-client.git
synced 2025-03-15 19:41:46 +00:00
208 lines
12 KiB
HTML
208 lines
12 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<!-- Generated by Apache Maven Doxia at Nov 25, 2014 -->
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<title></title>
|
|
<link rel="stylesheet" href="./css/apache-maven-fluido.min.css" />
|
|
<link rel="stylesheet" href="./css/site.css" />
|
|
<link rel="stylesheet" href="./css/print.css" media="print" />
|
|
<style>body{padding-top: 20px;}</style>
|
|
|
|
<script type="text/javascript" src="./js/apache-maven-fluido.min.js"></script>
|
|
|
|
|
|
<meta name="Date-Revision-yyyymmdd" content="20141125" />
|
|
<meta http-equiv="Content-Language" content="en" />
|
|
|
|
<!-- Google Analytics -->
|
|
<script type="text/javascript">
|
|
|
|
var _gaq = _gaq || [];
|
|
_gaq.push(['_setAccount', 'UA-23435653-1']);
|
|
_gaq.push(['_trackPageview']);
|
|
|
|
(function() {
|
|
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
})();
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
|
|
|
|
<div class="container-fluid">
|
|
|
|
<div id="breadcrumbs">
|
|
<ul class="breadcrumb">
|
|
|
|
|
|
<li class="">
|
|
<a href="http://rundeck.org" class="externalLink" title="Rundeck">Rundeck</a>
|
|
<li class="divider ">/</li>
|
|
</li>
|
|
<li class="">
|
|
<a href="./" title="Rundeck API - Java Client">Rundeck API - Java Client</a>
|
|
<li class="divider ">/</li>
|
|
</li>
|
|
<li class=""></li>
|
|
|
|
|
|
<li id="publishDate" class="pull-right">Last Published: 2014-11-25</li> <li class="divider pull-right">|</li>
|
|
<li id="projectVersion" class="pull-right">Version: 12.0</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="leftColumn" class="sidebar">
|
|
<div class="well">
|
|
|
|
|
|
<h5>RunDeck API - Java Client</h5>
|
|
<ul>
|
|
<li class="none">
|
|
<a href="index.html" title="Introduction">Introduction</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="status.html" title="Status">Status</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="faq.html" title="FAQ">FAQ</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="download.html" title="Download">Download</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="changes-report.html" title="Changelog">Changelog</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="apidocs/index.html" title="API Documentation">API Documentation</a>
|
|
</li>
|
|
</ul>
|
|
<h5>Scripting examples</h5>
|
|
<ul>
|
|
<li class="none">
|
|
<a href="scripting.html" title="Introduction">Introduction</a>
|
|
</li>
|
|
<li class="none">
|
|
<strong>Groovy</strong>
|
|
</li>
|
|
<li class="none">
|
|
<a href="jruby.html" title="JRuby">JRuby</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="jython.html" title="Jython">Jython</a>
|
|
</li>
|
|
</ul>
|
|
<h5>Project Documentation</h5>
|
|
<ul>
|
|
<li class="collapsed">
|
|
<a href="project-info.html" title="Project Information">Project Information</a>
|
|
</li>
|
|
<li class="collapsed">
|
|
<a href="project-reports.html" title="Project Reports">Project Reports</a>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
<div id="poweredBy">
|
|
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
|
|
<img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="bodyColumn" class="content">
|
|
<div id="contentBox">
|
|
|
|
<div class="section"><h2>Using the Rundeck API from Groovy scripts<a name="Using_the_Rundeck_API_from_Groovy_scripts"></a></h2></div><p>Here are some examples of what you can do with this lib and a few lines of <a class="externalLink" href="http://groovy.codehaus.org/">Groovy</a>.</p><p>We can use <a class="externalLink" href="http://groovy.codehaus.org/Grape">Grape</a> to download the lib (and its dependencies) from the <a class="externalLink" href="http://search.maven.org/">Maven Central Repository</a>, so you don't have to install anything manually (except Groovy, of course).</p><div class="section"><h3>Basic usage<a name="Basic_usage"></a></h3></div><p>Save the following script in a file named "<tt>rundeck.groovy</tt>", and execute it with "<tt>groovy rundeck.groovy</tt>". Feeling Groovy ? ;-)</p><div class="source"><pre class="prettyprint">// we use Grape (Ivy) to download the lib (and its dependencies) from Maven Central Repository
|
|
@Grab(group='org.rundeck', module='rundeck-api-java-client', version='12.0')
|
|
import org.rundeck.api.RundeckClient
|
|
|
|
rundeck = RundeckClient.builder().url("http://localhost:4440").login("admin", "admin").build()
|
|
|
|
println "Rundeck uptime : ${rundeck.systemInfo.uptime}"
|
|
println "All Rundeck projects : ${rundeck.projects}"
|
|
println "All Rundeck nodes : ${rundeck.nodes}"
|
|
println "All Rundeck jobs : ${rundeck.jobs}"
|
|
println "All Rundeck running executions : ${rundeck.runningExecutions}"
|
|
</pre></div><p>You can also <a href="./download.html">download</a> the lib and all its dependencies in 1 big jar file, and add it to your classpath before running your script : save the following script in a file named "<tt>rundeck.groovy</tt>", and execute it with "<tt>groovy -cp /path/to/rundeck-api-java-client-VERSION-jar-with-dependencies.jar rundeck.groovy</tt>".</p><div class="source"><pre class="prettyprint">import org.rundeck.api.RundeckClient
|
|
|
|
rundeck = RundeckClient.builder().url("http://localhost:4440").login("admin", "admin").build()
|
|
|
|
println "Rundeck uptime : ${rundeck.systemInfo.uptime}"
|
|
println "All Rundeck projects : ${rundeck.projects}"
|
|
println "All Rundeck nodes : ${rundeck.nodes}"
|
|
println "All Rundeck jobs : ${rundeck.jobs}"
|
|
println "All Rundeck running executions : ${rundeck.runningExecutions}"
|
|
</pre></div><div class="section"><h3>Authentication<a name="Authentication"></a></h3></div><p>Starting with Rundeck API 2, there are 2 ways to authenticate :</p><ul><li>the <b>login-based authentication</b> : with your login and password</li><li>the <b>token-based authentication</b> : with a unique token that you can generate from the Rundeck webUI</li></ul><div class="source"><pre class="prettyprint">// using login-based authentication (admin/admin is the default login/password for a new Rundeck instance) :
|
|
rundeck = RundeckClient.builder().url("http://localhost:4440").login("admin", "admin").build()
|
|
|
|
// using token-based authentication :
|
|
rundeck = RundeckClient.builder().url("http://localhost:4440").token("PDDNKo5VE29kpk4prOUDr2rsKdRkEvsD").build()
|
|
</pre></div><div class="section"><h3>Running a job<a name="Running_a_job"></a></h3></div><div class="source"><pre class="prettyprint">import org.rundeck.api.RundeckClient
|
|
rundeck = RundeckClient.builder().url("http://localhost:4440").login("admin", "admin").build()
|
|
|
|
// find a job from its name, group and project
|
|
job = rundeck.findJob("my-project", "main-group/sub-group", "job-name")
|
|
println "Found job with ID : ${job.id}"
|
|
|
|
// trigger a simple job with no options
|
|
execution = rundeck.triggerJob(job.id)
|
|
println "Execution started, you can follow it at the URL : ${execution.url}"
|
|
|
|
// or with options...
|
|
execution = rundeck.triggerJob("job-id", new Properties(option1: "value one", option2: "value two"))
|
|
|
|
// you can also override the nodes on which the job should execute
|
|
execution = rundeck.triggerJob("job-id", new Properties(opt: "value"), new Properties(tags: "prod+appserv"))
|
|
|
|
// last one : you can run a job and wait until its execution is finished :
|
|
execution = rundeck.runJob("job-id")
|
|
println "Execution finished ! Status : ${execution.status}, duration : ${execution.duration}"
|
|
</pre></div><div class="section"><h3>Running an ad-hoc command<a name="Running_an_ad-hoc_command"></a></h3></div><div class="source"><pre class="prettyprint">import org.rundeck.api.RundeckClient
|
|
rundeck = RundeckClient.builder().url("http://localhost:4440").login("admin", "admin").build()
|
|
|
|
// trigger the execution of the "uptime" command on the Rundeck server
|
|
execution = rundeck.triggerAdhocCommand("my-project", "uptime")
|
|
|
|
// run the "uptime" command on all unix nodes
|
|
execution = rundeck.runAdhocCommand("my-project", "uptime", new Properties(os-family: "unix"))
|
|
</pre></div><div class="section"><h3>Running an ad-hoc script<a name="Running_an_ad-hoc_script"></a></h3></div><div class="source"><pre class="prettyprint">import org.rundeck.api.RundeckClient
|
|
rundeck = RundeckClient.builder().url("http://localhost:4440").login("admin", "admin").build()
|
|
|
|
// trigger the execution of a custom bash script on the Rundeck server
|
|
execution = rundeck.triggerAdhocScript("my-project", "/tmp/my-script.sh")
|
|
|
|
// run a bash script (with options) on all unix nodes
|
|
execution = rundeck.runAdhocCommand("my-project", "/tmp/my-script-with-options.sh", new Properties(option1: "value one"), new Properties(os-family: "unix"))
|
|
</pre></div><div class="section"><h3>Exporting jobs<a name="Exporting_jobs"></a></h3></div><div class="source"><pre class="prettyprint">import org.rundeck.api.RundeckClient
|
|
rundeck = RundeckClient.builder().url("http://localhost:4440").login("admin", "admin").build()
|
|
|
|
rundeck.exportJobsToFile("/tmp/jobs.xml", "xml", "my-project")
|
|
rundeck.exportJobToFile("/tmp/job.yaml", "yaml", "job-id")
|
|
</pre></div><div class="section"><h3>Importing jobs<a name="Importing_jobs"></a></h3></div><div class="source"><pre class="prettyprint">import org.rundeck.api.RundeckClient
|
|
rundeck = RundeckClient.builder().url("http://localhost:4440").login("admin", "admin").build()
|
|
|
|
result = rundeck.importJobs("/tmp/jobs.xml", "xml")
|
|
println "${result.succeededJobs.size} jobs successfully imported, ${result.skippedJobs.size} jobs skipped, and ${result.failedJobs.size} jobs failed"
|
|
</pre></div><div class="section"><h3>And more...<a name="And_more..."></a></h3></div><p>See the API documentation of the <a href="./apidocs/reference/org/rundeck/api/RundeckClient.html">RundeckClient</a> class for more interactions with your Rundeck instance...</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="footer">
|
|
<div class="container-fluid">
|
|
<div class="row span16">Copyright © 2011-2014.
|
|
All Rights Reserved.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|