How to add/remove Task variables from User Input Tasks using Jython API


Shashank Srivastava -

You have a few Release variables & you want to add &/or remove to/from User Input Tasks using Jython API from within a Jython Script task.

XL Release

Steps to Perform

1. Create your Release Variables. This can be done manually or using Jython API/ From within Jython script task.

2. Create 2 user Input tasks A & B. This can, again, be done manually or using Jython API. My script does everything automatically.

3. Below is the script that you can use to add/remove Task variables. I have put relevant comments to make the script more descriptive.

#Creating 3 Release variables first.
print "Creating a Release variable userName... \n"
myvar = Variable('userName', 'shashank')
releaseApi.createVariable(, myvar)
var_userName = releaseApi.getVariables(
print "Below is newly created variable. \n"
print var_userName

print "\n Creating a Release variable passWord... \n"
myvar2 = Variable('passWord', 'password')
releaseApi.createVariable(, myvar2)
varList = releaseApi.getVariables(
var_passWord = varList[1]
print "Below is newly created variable. \n"
print var_passWord

print "\n Creating another Release variable hostName... \n"
myvar3 = Variable('hostName', 'mysql-server')
releaseApi.createVariable(, myvar3)
varList = releaseApi.getVariables(
print "Printing Variables list... \n"
print varList
print "\n"
var_hostName = varList[2]
print "Below is newly created variable. \n"
print var_hostName

#Creating a User Input task & adding variables to it from Release variables.
print "\n Creating a User Input task A... \n"
phase = getCurrentPhase()
task = taskApi.newTask("xlrelease.UserInputTask")
task.title = "User Input task A"
taskApi.addTask(, task)
print "User Input task created. \n"

#Creating a User Input task, adding variables to it from Release variables & then removing the 3rd variable var_hostName.
print "\n Creating a User Input task B... \n"
phase = getCurrentPhase()
task2 = taskApi.newTask("xlrelease.UserInputTask")
task2.title = "User Input task B"
taskApi.addTask(, task2)
print "User Input task2 created. \n"
print "Printing User Input task Variables...\n"
print task2.variables
print "\n Removing User Input task variable %s" % var_hostName.getLabel()
print "\n"
task2.variables = [x for x in task2.variables if !=]
print "Variable removed from 2nd User Input task."




Caveats (if any)

This script intentionally removes the first Task variable. You can manipulate it to suit your needs. 

Additional Information

Refer to XebiaLabs documentation for more information.

 kb, how-to, xl-release, Jython API, scripts
Have more questions? Submit a request
Powered by Zendesk