YAML Snippets Reference in Release
This reference includes some useful snippets to get started when writing DevOps as Code YAML files that can be applied to Release.
This section includes some useful snippets to get started when writing YAML files to apply to Release.
Create a Shared Configuration item
Set up a reusable server connection in Shared Configuration:
apiVersion: xl-release/v1
kind: Templates
spec:
- name: Deploy
type: xldeploy.XLDeployServer
url: http://xl-deploy:4516
username: !value XL_DEPLOY_USERNAME
password: !value XL_DEPLOY_PASSWORD
Manage templates
Create a template
Create a basic template with one manual task:
apiVersion: xl-release/v1
kind: Templates
spec:
- name: Sample release
type: xlrelease.Release
phases:
- name: DEV
type: xlrelease.Phase
tasks:
- name: Do something
type: xlrelease.Task
Create a folder structure
Create nested folders using the directory
construct. You can create templates directly under the directory
:
apiVersion: xl-release/v1
kind: Templates
spec:
- directory: My folder
children:
- directory: Subfolder
children:
- name: My subtemplate
type: xlrelease.Release
Folders will be created if they don't already exist.
Create a template in an existing folder
If a folder is already present, you can create a template in it:
apiVersion: xl-release/v1
kind: Templates
metadata:
home: My folder
spec:
- name: My template
type: xlrelease.Release
Set descriptions in Markdown
Set a Markdown description by using the |
construct from YAML:
apiVersion: xl-release/v1
kind: Templates
spec:
- name: My template
type: xlrelease.Release
description: |
This is the standard release process. See our wiki <link>
Template properties
Define template properties:
apiVersion: xl-release/v1
kind: Templates
spec:
- name: My template
type: xlrelease.Release
description: |
This is the standard release process. See our wiki <link>
scheduledStartDate: 2018-11-01T08:00:00Z
scriptUsername: admin
scriptUserPassword: admin
tags:
- Standard release
Variable usage
Variables are defined at the template level and can be referenced in tasks with the ${...}
syntax:
apiVersion: xl-release/v1
kind: Templates
spec:
- name: My release template
type: xlrelease.Release
variables:
- key: version # Define ${version} variable
label: Version
description: The version of this release
type: xlrelease.StringVariable
requiresValue: true
showOnReleaseStart: true
phases:
- name: DEV
type: xlrelease.Phase
tasks:
- name: Develop ${version} # Use ${version} variable
type: xlrelease.Task
Here is a list of examples for all variable types:
variables:
- key: stringVariable
type: xlrelease.StringVariable
value: Hello world
- key: passwordVariable
type: xlrelease.PasswordStringVariable
- key: booleanVariable
type: xlrelease.BooleanVariable
value: true
- key: numberVariable
type: xlrelease.IntegerVariable
value: 42
- key: listVariable
type: xlrelease.ListStringVariable
value:
- One
- Two
- Three
- key: mapVariable
type: xlrelease.MapStringStringVariable
value:
1: I
2: II
3: III
- key: setVariable
type: xlrelease.SetStringVariable
value:
- Apples
- Pears
- Oranges
- key: listBoxVariable
type: xlrelease.StringVariable
valueProvider:
type: xlrelease.ListOfStringValueProviderConfiguration
values:
- One
- Two
- Three
All task properties you can set on any task
Here is an overview of properties you can set on a task:
tasks:
- name: My task
type: xlrelease.Task
description: |
**Markdown** description.
owner: admin
team: Release Admin
scheduledStartDate: 2018-11-01T08:00:00Z
dueDate: 2018-11-01T10:00:00Z
plannedDuration: 7200
delayDuringBlackout: true
flagStatus: ATTENTION_NEEDED # Possible values: OK, ATTENTION_NEEDED, AT_RISK
flagComment: This task fails often
tags:
- Task tag
watchers:
- admin
Parallel and Sequential groups
Here is an example of Parallel and Sequential groups:
tasks:
- name: Parallel execution
type: xlrelease.ParallelGroup
tasks:
- name: Task 1a
type: xlrelease.Task
- name: Task 1b
type: xlrelease.Task
- name: Sequential execution
type: xlrelease.SequentialGroup
tasks:
- name: Task 1
type: xlrelease.Task
- name: Task 2
type: xlrelease.Task
Use a failure handler
Use this construct to skip a task when it fails:
tasks:
- name: Deploy to DEV
type: xldeploy.Deploy
taskFailureHandlerEnabled: true
taskRecoverOp: SKIP_TASK
This snippet runs a script that tries the task three times before it fails:
tasks:
- name: Try 3 times
type: xlrelease.Task
taskFailureHandlerEnabled: true
taskRecoverOp: RUN_SCRIPT
failureHandler: |
if (releaseVariables['attempt'] < 3):
releaseVariables['attempt'] = releaseVariables['attempt'] + 1
taskApi.retryTask(getCurrentTask().getId(), "Retrying task from failure handler.")
else:
taskApi.skipTask(getCurrentTask().getId(), "Skipped task from failure handler.")
Create Python and Groovy script tasks
These snippets will create Script tasks. Use the YAML |
construct for the script section.
Jython script:
tasks:
- name: Sleep in Jython
type: xlrelease.ScriptTask
script: |
import time
time.sleep(5)
Groovy script:
tasks:
- name: Sleep in Groovy
type: xlrelease.GroovyScriptTask
script: |
sleep(5000)
Create a release task
The create release task starts a release. You do not need to define the output variable in the variable section as it will be created automatically.
tasks:
- name: Sub release
type: xlrelease.CreateReleaseTask
newReleaseTitle: My subrelease
template: My template
folder: My folder/Subfolder
templateVariables:
- key: version
value: 1.0
type: xlrelease.StringVariable
Gate task with conditions
Add conditions to a Gate task like this:
tasks:
- name: Verify before deployment
type: xlrelease.GateTask
conditions:
- name: Application is tested
type: xlrelease.GateCondition
- name: Environment is available
type: xlrelease.GateCondition
checked: true
Connect Release to Deploy
Set up a connection from Release to Deploy using this snippet:
apiVersion: xl-release/v1
kind: Templates
spec:
- name: Deploy
type: xldeploy.XLDeployServer
url: http://xl-deploy:4516
username: !value XL_DEPLOY_USERNAME
password: !value XL_DEPLOY_PASSWORD
Simple Deploy deployment task
Here is a simple example of a task that triggers a deployment in Deploy:
tasks:
- name: Deploy REST-o-rant
type: xldeploy.Deploy
server: Deploy
deploymentPackage: rest-o-rant-api-docker/1.1
deploymentEnvironment: Environments/Local Docker Engine
The names correspond to items defined in an Deploy server so you must have a Shared Configuration object called Deploy
already defined in Release.
Manage permissions
You can specify permissions-related details in YAML. This section includes YAML snippets for users, roles and global permissions.