Automated Weblogic versioned app deployment

We had a need to automate deployments with a versioned app. You can place an entry in the MANIFEST.MF for “Weblogic-Application-Version: v14”, or whatever, or you can dynamically assign it at deployment time.

What is below will do the latter in an WLST script.

In this case, we had a fixed location for our EAR, with a fixed name by environment. We ensure the deployment name matches the EAR name, and as such, could simply parse the deployments returned in WLST and increment the highest one by 1. We could also retire the lowest numbered deployment.

import sys,os

#----------------------------------------------------------------------------------

#we store our admin login credentials, so only need the URL to connect
connect(url='t3://admin_host:7001')

max = 0
min = pow(2,32)
l = ls('AppDeployments',returnMap='true')
total = 0
for i in l:
  if i.find(sys.argv[1] + "#") > -1:
    total = total + 1
    current = i.split("#")
    if int(current[1]) > int(max):
      max = int(current[1])
    if int(current[1]) < int(min):
      min = int(current[1])

max = max + 1

TARGETS = ""

if total == 0:
  TARGETS = sys.argv[1]
  print "No targets defined for " + sys.argv[1] + ", cannot proceed."
  sys.exit(1)
else:
  if total == 2:
    undeploy(sys.argv[1] + '#' + str(min))
  elif total == 1:
    print "Found less than two deployments, not undeploying any versions"


  cd('/AppDeployments/' + sys.argv[1] + '#' + str(max - 1) + '/Targets')
  LIST = ls(returnMap='true')

  for TARGET in LIST:
    TARGETS = TARGETS + "," + TARGET
  TARGETS=TARGETS[1:]
  print TARGETS

progress = deploy(sys.argv[1],
                  '/opt/weblogic/' + sys.argv[1] + '.ear',
                  stageMode='stage',
                  versionIdentifier=max,
                  timeout=1200000,
                  targets=TARGETS)

print "Deployment progress = " + str(progress)
dumpStack()

#----------------------------------------------------------------------------------

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.