Skip to content

Instantly share code, notes, and snippets.

@fowlie
Last active August 29, 2015 14:00
Show Gist options
  • Save fowlie/11251852 to your computer and use it in GitHub Desktop.
Save fowlie/11251852 to your computer and use it in GitHub Desktop.
XebiaLabs XL Deploy Install Latest Package
import sys
if len(sys.argv)!=4:
print ''
print 'Usage: ' + sys.argv[0] + ' [ApplicationName] [FromEnvironment] [ToEnvironment]'
print ''
print 'The following example will upgrade WAS STEST with the package installed in WAS ITEST:'
print sys.argv[0] + ' webshop-deployit-bundle WAS/WEBSHOP_NO/it-was8-webshop-no WAS/WEBSHOP_NO/st-was8-webshop-no'
else:
# Read input arguments
packageName = sys.argv[1]
fromEnv = sys.argv[2]
toEnv = sys.argv[3]
# Find the specific package version that is deployed in the FromEnvironment
apps = repository.search('udm.DeployedApplication', 'Environments/' + fromEnv)
appInstalled = 0
for app in apps:
package = repository.read(app)
if package.name == packageName:
appInstalled = 1
break
if appInstalled == 0:
print 'ERROR: ' + packageName + ' is not deployed to ' + fromEnv
sys.exit(1)
# Prepare upgrade
environment = repository.read('Environments/' + toEnv + '/' + packageName)
deploymentRef = deployment.prepareUpgrade(package.version, environment.id)
# Log upgrade deployment info
print deploymentRef
# Create a deployment task, it will be visible also in GUI
taskRef = deployment.deploy(deploymentRef)
# Get steps of the planned deployment task
firstTask=tasks.steps(taskRef.id)
print 'Steps:'
for step in firstTask.getSteps():
print ' > %s' % (step,)
# Start deployment task
deployit.startTaskAndWait(taskRef.id)
# Check if the task is listed as unfinished
for task in deployit.listUnfinishedTasks():
if task.id == taskRef.id:
print 'ERROR: Deployment failed with status ' + task.getState()
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment