Skip to main content
DevOps icon showing cogs

This post is from the XebiaLabs blog and has not been updated since the original publish date.

Last Updated Dec 09, 2014 — DevOps Expert

Defining XL Deploy Infrastructure with Dojo and JavaScript


XL Deploy's REST API can be easily called from Dojo/JavaScript scripts to define new infrastructure in the repository.  Earlier articles have already explained the basics using command-line curl examples, so let's look at how Dojo and JavaScript can be used to perform the same sorts of operations.

Here is the function that makes the call to XL Deploy's REST API:

function defineConfigItem(ciPath, postDataText) {
  // console.log("Starting defineConfigItem()");
    url: "http://localhost:4516/XL Deploy/repository/ci/" + ciPath,
    user: "admin",
    password: "admin",
    headers: {"Content-Type": "application/xml"},
    sync: true,
    postData: postDataText,
    //timeout: 10000,
    handleAs: "xml",
    load: function(result, ioargs) {
      dojo.publish("xldStatus", [{message: "DefineConfigItem HTTP status code " + ioargs.xhr.status,
      type: "message", duration: 2000}]);
    error: commonError
 // console.log("Exiting defineConfigItem()");
As you can see, we use a POST call with the path to the new configuration item at the end of the url.  As a reminder, XL Deploy's paths can be easily copied from the GUI by going into edit mode on the CI, right-clicking the id field and selecting Copy.  Besides passing in the path, we also pass the post data as a string in XML format, as in this example:
<overthere.SshHost id="Infrastructure/my-new-ci">
And of course we must code the rest of the parameters required for xhrPost.  The url, username, password and headers operate as in any HTTP call. You have a choice between sync (wait for the call to return) and timeout (execute asynchronously but error out after the specified number of milliseconds).  The handeAs parameter refers to what is returned, so it is superfluous in this case.  The last two properties are callbacks:, load defines a function called for a good result and error defines an "errback" function called otherwise. The remainder of the scripting serves to supply properly formatted data to defineConfigItem.  The xldDriver function receives a number of parameters derived from an input source, assembles the postDataText XML string, and makes the function call.  Any XML formatter can stand in here, but let's just concatenate tags and values the old-fashioned way for now:
function xldDriver(ciPath,ciType,deploymentGroup,os,connectionType,address,myPort,username,password,sudoUsername) {
  // console.log("0: Executing xldDriver");
  postDataText =
    "<" + ciType + " id='" + ciPath + "'>" +
    "<deploymentGroup>" + deploymentGroup + "</deploymentGroup>" +
    "<os>" + os + "</os>" +
    "<connectionType>" + connectionType + "</connectionType>" +
    "<address>" + address + "</address>" +
    "<port>" + myPort + "</port>" +
    "<username>" + username + "</username>" +
    "<password>" + password + "</password>" +
    "<sudoUsername>" + sudoUsername + "</sudoUsername>" +
    "</" + ciType +">";
 defineConfigItem(ciPath, postDataText);
And commonError provides a means of alerting the user to bad return codes from our HTTP calls:
function commonError(text, ioargs) {
 error = true;
 dojo.publish("xhrError", [{message: "HTTP status code " + ioargs.xhr.status, type: "error", duration: 2000}]);
 return text;
Note that we use dojo.publish to publish good and bad results to the dojo.Toaster objects xldStatus and xhrError respectively.  With these three functions, any provisioning tool that supports JavaScript calls can communicate its results directly to XL Deploy.

More from the Blog

View more
Ascension Launch Banner
Apr 26, 2022

Get ready for peak performance with’s newest AI-Powered DevOps Platform Ascension Release

Today, is excited to announce our latest AI-Powered DevOps ...
Read More
Jan 24, 2022 Value Stream Delivery for SAFe®: The key to amazing business outcomes

The Scaled Agile Framework (SAFe) is the world’s leading framework for ...
Read More
Dec 09, 2021

How SaaS and cloud-based solutions helped the U.S. Department of Veterans Affairs achieve digital transformation

Modernizing legacy systems was an ongoing goal for the U.S. Department ...
Read More
Nov 29, 2021

Increase velocity and reduce risk with AI and machine learning

Artificial Intelligence (AI) and machine learning (ML) have proven use ...
Read More
Contact Us