-
Notifications
You must be signed in to change notification settings - Fork 10
Launching Groovy scripts that invoke the REST API from a process step
The groovy-sample-scripts-UCD wiki describes how to use the sample Groovy scripts provided in this repository.
There are many libraries that can be used to invoke REST APIs. Groovy itself offers extensions to the URL class:
http://docs.groovy-lang.org/latest/html/groovy-jdk/java/net/URL.html
The examples in this repository use libraries that are part of each IBM UrbanCode Deploy agent installation.
The UrbanCode Deploy udclient contains the Apache HttpCore library (HttpCore 4.3.2, as of UrbanCode Deploy 6.2.3.1). For more information, see: http://hc.apache.org/downloads.cgi
The udclient is included in the UrbanCode Deploy Agent by default, so there are no libraries you need to install on the target.
The udclient is located in:
agent/opt/udclient/udclient.jar
You can run the scripts provided in this repository from a UrbanCode Deploy process, as follows:
-
Create a component or generic process in UrbanCode Deploy.
-
Add a step of type: "Create File" with a name like: myGroovyScript.groovy. The contents will be taken from one of the code examples in this repository. Note that using this step ensures that the UrbanCode Deploy variables contained in the script will be resolved by the UrbanCode Deploy server before running the script. If you omit this step and reference the script directly from the filesystem, then the script will fail with a error like:
groovy.lang.MissingPropertyException: No such property: server for class: myGroovyScript
-
Create a "Shell" step and enter this command (all on one line):
${p:agent/GROOVY_HOME}${p:agent/sys.file.separator}bin${p:agent/sys.file.separator}groovy -cp ${p:agent/AGENT_HOME}${p:agent/sys.file.separator}opt${p:agent/sys.file.separator}udclient${p:agent/sys.file.separator}udclient.jar myGroovyScript.groovy
This step will add the udclient.jar to the classpath of the Groovy runtime. It works on all platforms because it retrieves the file separator from the agent properties
(${p:agent/sys.file.separator}
).
- In the Groovy script, you can use code that leverages the Apache HttpCore libraries to make REST calls to the UrbanCode Deploy APIs.
If you are running the scripts on a machine that requires an http proxy to reach the UrbanCode Deploy Server URL, you must set the following environment variables before running the script from thew command line:
PROXY_HOST
PROXY_PORT
If you run the script from a UrbanCode Deploy process, on an Agent that is connecting to the Server through a Relay, these variables will be set automatically, and they will refer to the host and port of the Relay http proxy.