This page contains some useful snippets to get started when writing a DevOps as Code YAML file for XL Release.

Shared Configuration

Create a Shared Configuration item

Set up a reusable server connection in Shared Configuration like this:

apiVersion: xl-release/v1
kind: Templates
spec:
- name: XL Deploy
  type: xldeploy.XLDeployServer
  url: http://xl-deploy:4516
  username: !value XL_DEPLOY_USERNAME
  password: !value XL_DEPLOY_PASSWORD

Templates

Create a template

Here is 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 with this snippet:

apiVersion: xl-release/v1
kind: Templates
metadata:
  home: My folder
spec:
- name: My template
  type: xlrelease.Release

Set descriptions in Markdown

The most convenient way to set a Markdown description is 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](http://wiki.example.com/process)

Template properties

Here is a template with various properties:

apiVersion: xl-release/v1
kind: Templates
spec:
- name: My template
  type: xlrelease.Release
  description: |
    This is the standard release process. See our [wiki](http://wiki.example.com/process)
  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. Here is an example:

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 a 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 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
      templateId: My template
      folderId: My folder/Subfolder
      templateVariables:
      - key: version
        value: 1.0
        type: xlrelease.StringVariable

Gate task with conditions

Add conditions to a Gate task like this: <!— source: YAML

apiVersion: xl-release/v1 kind: Templates metadata: home: My folder spec:

  • name: Gate conditions type: xlrelease.Release phases:
    • name: DEV type: xlrelease.Phase –> source: YAML ``` 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 XL Release to XL Deploy

Set up a connection from XL Release to XL Deploy using this snippet:

apiVersion: xl-release/v1
kind: Templates
spec:
- name: XL Deploy
  type: xldeploy.XLDeployServer
  url: http://xl-deploy:4516
  username: !value XL_DEPLOY_USERNAME
  password: !value XL_DEPLOY_PASSWORD

Simple XL Deploy deploy task

Here is a simple example of a task that triggers a deployment in XL Deploy:

    tasks:
    - name: Deploy REST-o-rant
      type: xldeploy.Deploy
      server: XL Deploy
      deploymentPackage:  rest-o-rant-api-docker/1.1
      deploymentEnvironment: Environments/Local Docker Engine

Note: The names correspond to items defined in an XL Deploy server so you must have a Shared Configuration object called XL Deploy already defined in XL Release.

Releases

Create a release

Create a release based on a template directly from YAML using the Release kind:

apiVersion: xl-release/v1
kind: Release
spec:
  name: My folder/My release
  template: My release template
  variables:
    version: '1.0'