Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

XL Release Tutorial: Variables

Using a List variable as a value in the List box variable types

You can create a List variable and use it as a possible value for a List box variable.

  1. Create a global variable or a release variable with the type List.
  2. When you create a new variable and select the type List box, click the button next to the Possible values to switch between a list of normal values or a variable of type List.List box variable
  3. Select the second option and choose a List type variable.
  4. Click Save.

You can use the List box variable in templates, releases, or tasks allowing users to select the values from predefined List variable.

Using lists of Applications or Environments in the List box variable types

You can choose a list of Applications or Environments to be used as possible values for a List box variable.

Please specify the run-as user and password on the template properties as those credentials will be used to retrieve the available Applications and Environments.

Note: Applications or environments will only be retrieved when the new release is being created and during the User Input task. In all other cases – such as manually changing variable values in either a Template or Release – the list of values will be empty.

Dynamically populating a List box variable type using a custom script

You can use a script to dynamically retrieve possible values inside a List box variable.

  1. Create a new List box variable.
  2. Select Value provider as the Value provider type.List box variable_with_value_provider
  3. Select the Script value provider.
  4. Depending on the selected script, you will have different input fields. The script will be evaluated when creating a release.
  5. Click Save.

Note: Applications or environments will only be retrieved when the new release is being created and during the User Input task. In all other cases – such as manually changing variable values in either a Template or Release – the list of values will be empty.

Creating a custom script value provider

Creating a new script value provider is similar to the Plugin tasks. For a more detailed explanation of how to extend the Release type system, see Defining a custom task.

Example script value provider

In the synthetic.xml file, you must extend xlrelease.JythonProvider or xlrelease.GroovyProvider:

<synthetic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.xebialabs.com/deployit/synthetic"
       xsi:schemaLocation="http://www.xebialabs.com/deployit/synthetic synthetic.xsd">

  <type type="test.Test2ValueProvider" extends="xlrelease.JythonProvider" label="Sample value provider with CI ref"
            description="This value provider has CI ref parameter that points to JIRA server.">
      <property name="jiraServer" label="JIRA server" referenced-type="jira.Server" kind="ci" description="JIRA server to use" />
      <property name="username"  required="false" description="Overrides the username used to connect to the server"/>
      <property name="password" password="true" required="false" description="Overrides the password used to connect to the server"/>
  </type>

</synthetic>

You can store value provider scripts in the ext or plugins directory of the Release server.

  • Use ext when you are developing a custom value provider. The ext directory contains custom type definitions in the synthetic.xml file. Scripts are placed in the subdirectories of ext.
  • The plugins directory contains bundled plugins that are packaged in a single zip file with the .jar extension.

For the value provider defined above, Release will try to find and execute the python script at this location: test/Test2ValueProvider.py. Value provider scripts must return a list of objects in the variable named result.

Note: The properties of the value provider will be injected into the script as well as a dictionary. As a result, you do not need to access the properties as valueProvider.jiraServer but use jiraServer, instead.

The following script can be used to display the title of the JIRA server passed as a parameter to the value provider defined above:

# let's connect to the provided jiraServer
from xlrelease.HttpRequest import HttpRequest
# example of request to the Jira server
req = HttpRequest(jiraServer)
# ...
result = [jiraServer["title"]]
# or
# result = [valueProvider.jiraServer.title]

You can add the following properties to the <type> element to further customize your value provider:

  • scriptLocation: Specifies a custom script location that overrides the default rules.

This is an example of a value provider that generates a range of numbers:

<synthetic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.xebialabs.com/deployit/synthetic"
       xsi:schemaLocation="http://www.xebialabs.com/deployit/synthetic synthetic.xsd">

    <type type="test.TestValueProvider" extends="xlrelease.JythonProvider" label="Sample script value provider"
          description="This value provider has two parameters for range.">
        <property name="param1" label="Lower bound" default="1" description="Minimum value." required="false" />
        <property name="param2" label="Upper bound" default="5" description="Maximum value." required="false" />
    </type>

</synthetic>

Place the corresponding script into test/TestValueProvider.py:
def generateRange():
    t = range(long(valueProvider.param1), long(valueProvider.param2))
    return t

result = generateRange()

Refernce

  • https://docs.digital.ai/bundle/devops-release-version-v.22.2/page/release/how-to/configure-global-variables.html
Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
venkatesh
venkatesh
2 years ago

How do you add dynamic generated values like 1-10 and assign to the list box?

1
0
Would love your thoughts, please comment.x
()
x