Importing a deployment archive from a URL
Many clients store packages in a central repository such as Nexus. To deploy them using XL Deploy, they need to be imported there first. XL Deploy does not have an option to do this directly (from the CLI or GUI), but using Python, you can easily write a script to do it which will run in the XL Deploy CLI. Here's an example:
import urllib2 # # This script is an example of how to import a file from a repository (nexus). # First, the file is downloaded to the local filesystem. Then, it is imported # into XL Deploy. # # Setup handling of basic authentication def setupBasicAuth(): # create a password manager password\_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() # Add the username and password. top\_level\_url = "http://dexter.xebialabs.com/nexus" password\_mgr.add\_password(None, top\_level\_url, "username", "password") # create "opener" (OpenerDirector instance) handler = urllib2.HTTPBasicAuthHandler(password\_mgr) opener = urllib2.build\_opener(handler) # Install the opener. # Now all calls to urllib.urlopen use our opener. urllib2.install\_opener(opener) # Download file def downloadFile(): # Open the URL of the resource you want to download f = urllib2.urlopen("http://dexter.xebialabs.com/nexus/content/repositories/releases/com/xebialabs/deployit/plugins/was-plugin/3.0.1/was-plugin-3.0.1.jar") # Open our local file for writing local\_file = open("/tmp/tmpfile.jar", "w") # Write to our local file local\_file.write(f.read()) local\_file.close() # # Main script # setupBasicAuth() downloadFile() # Import it into Deployit deployit.importPackage("/tmp/tmpfile.jar")
Please sign in to leave a comment.