This document describes the functionality provided by the XL Release xlr-variable-setter-plugin.
See the XL Release reference manual for background information on XL Release and release automation concepts.
This is a 'See It Work' plugin, meaning it has been enhanced to include functionality that makes it easy to spin up and configure a dockerized version of the XebiaLabs platform with this plugin installed. Using the provided test data, you can then try out the plugin features. This is useful for familiarizing yourself with the plugin functionality, for demonstrations, testing and for further plugin development.
The plugin code base also includes a gradle task for automatic integration testing.
The plugin provides a number of ways to dynamically populate Release variables. The first task, Set Vars From Remote Files provides the ability to populate Release Variables with values retrieved from remote JSON, property, XML, or YAML files that are accessible via URL. One use case example is a single XL Release Template, used for multiple projects which are stored in multiple repositories with project specific Release Variable values stored in a JSON, property, XML, or YAML file within each repository. The plugin task Set Vars From Remote Files will retrieve and parse each specified file and then set the values of designated Release Variables.
A second task, Set Vars From Var, has been added. This task will parse JSON or XML that has been stored in a Release Variable and uses the values found therein to populate other Release Variables. A possible use case would be to store the JSON returned in the POST body of a webhook call used start a release in a Release Variable and then use the task to parse that JSON and set the values of other Release Variables to be used downstream in the Release.
IMPORTANT: The plugin will set values only for pre-existing Release Variables. The plugin does not create new variables. Part of the template or release creation process will involve creating these variables with empty or default values that will then be replaced when the tasks are invoked.
XL_RELEASE_SERVER/plugins/__local__
directory.IMPORTANT! Any template or release that is configured to use tasks from this plugin must run as a user with sufficient permissions to update Release Variables.
This updates release variables with values retrieved from a file.
Begin by creating one or more property, XML, or YAML files and put them where they can be retrieved using a URL (a Git repository, for example). Use the following examples as a guideline for your files.
NOTE:
variables
declaration. The key value corresponds to the Release Variable name configured in XL Release, and the type designation corresponds to the type of the Release Variable. The type must have one of these three values xlrelease.StringVariable
, xlrelease.BooleanVariable
, or xlrelease.IntegerVariable
. The type xlrelease.BooleanVariable
corresponds to the 'Checkbox' type in XL Release.See below, under heading - Variable Naming Convention for the 'Set Vars From Var' Task
Create one or more Release Variables of type Text, Number, or Checkbox (Boolean). The plugin will populate only existing variables. It will not create new variables. Name the variable to match the name used in the file.
NOTE: Follow this XPATH-like naming convention for variables that will be retrieved from XML files:
NOTE: Release Variables that will be updated when JSON files parsed are named similarly to those updated from XML files.
Configure the variable with a name and a type and an optional default value. Uncheck the 'Required' and 'Show on Create Release form' options.
The xlr-variable-setter-plugin has a task - Set Vars From Remote Files.
This task updates Release Variables with values retrieved from a JSON or XML source that has been stored in another Release Variable. The JSON or XML source stored in the source Release Variable is parsed by the 'Set Vars from Var' task which then updates other specifically named Release Variables. An example of a JSON source might be the JSON returned in the POST body of a webhook call to start a release. IMPORTANT: The plugin will set values only for pre-existing Release Variables. The plugin does not create new variables. Part of template or release creation process will involve creating these variables with empty or default values that will then be replaced when the release runs.
The Release Variable you create to hold the source JSON or XML can have any name but, as mentioned previously, the Release Variables you want to set via the 'Set Vars from Var' task must follow a specific naming pattern. As complex JSON or XML objects are parsed, a name is built from the path. The Release Variable you wish to set must be named to match that path. You can configure an optional prefix to be added to the path so the variable will have a more meaningful name. Please see the screenshots and example below.
Below is a sample commit message from BitBucket. Say you wanted the first author's email address in a release variable. You can see this is the first element in the 'values' array. The email address is within the 'author' object. The JSON parser would build a name from as follows:
<name prefix>_values_0_author_emailAddress
where:
Assume that you have created a Release Variable named 'bitbucketResponseSourceJSON' and have set up the bitbucket task to store the response JSON in that variable. If, within the 'Set Vars From Var' task configuration, you set the prefix to be 'bitbucket', you should then create an empty Release Variable of type 'Text' with a name of 'bitbucket_values_0_author_emailAddress'. When the 'Set Vars From Var' task in runs, the contents of 'bitbucketResponseSourceJSON' Release Variable will be parsed and the Release Variable bitbucket_values_0_author_emailAddress will be populated with the value sruiz@atlassian.com.
{
"size": 2,
"limit": 25,
"isLastPage": true,
"values": [
{
"id": "01f9c8680e9db9888463b61e423b7b1d18a5c2c1",
"displayId": "01f9c86",
"author": {
"name": "Seb Ruiz",
"emailAddress": "sruiz@atlassian.com"
},
"authorTimestamp": 1334730200000,
"message": "NONE: Add groovy as java synhi\n+review @aahmed",
"parents": [
{
"id": "06a499d51107533a4f24a3620280edbb342d89b7",
"displayId": "06a499d"
}
],
"attributes": {}
},
{
"id": "c9d6630b88143dab6a922c5cffe931dae68a612a",
"displayId": "c9d6630",
"author": {
"name": "Pierre-Etienne Poirot",
"emailAddress": "pepoirot@atlassian.com"
}
}
],
"start": 0,
"filter": null,
"nextPageStart": 2
}
In summary, these are the steps you would take to setup a 'Set Vars From Var' task:
Build and package the plugins with...
./gradlew assemble
./gradlew clean integrationTest
The test will set up a temporary xlr/mockserver testbed using docker. The mockserver is used to serve up the property or YAML files. After testing is complete, the test docker containers are stopped and removed.
NOTE:
./gradlew clean build
docker-compose up
After XLR starts up, log in using the admin / admin credentials and then use the XLR 'Import Template' feature to import the template found in the src/test/resources/docker/initialize/data directory. You can then create a release and run the test example.
To shut down and remove the docker containers, in the src/test/resources/docker/initialize/data directory, run
docker-compose down