Generating DSL Scripts

3 minute readReferenceDeveloper productivity

There are three ways to generate DSL scripts, based on your needs:

Single objects

Via UI

You can export any object such as a pipeline, application or microservice, environments, release, and so on, to a DSL file to represent its definition as code. You can then store the file in a source code repository of your choice.

The DSL-based representation of any object lets you recreate that state of the object at any point. For example, let’s say you have a pipeline named Heatclinic pipeline DSL and you want to be able to recreate its current state at any point in the future. Using the DSL Export feature, you can export the current definition for this pipeline as code to a DSL file.

Figure 1. The actions menu
Figure 1. The actions menu
  1. Select DSL Export from the actions menu. The Export DSL menu displays.

  2. Select options from the Export DSL menu as required.

    Suppress Nulls

    Select to suppress both object and custom properties with null values in the exported DSL. If not selected, all properties are returned, subject to the Suppress Defaults setting.

    To override null values for custom properties from being suppressed, set the server setting, disableNotSuppressNullsOption, to true:

    ectool setProperty /server/settings/disableNotSuppressNullsOption true

    Suppress Defaults

    Select to suppress object and custom properties with default values in the exported DSL.

    Suppress Parent

    Select to exclude the object’s parent references in the exported DSL.

    Include ACLs

    Select to include each object’s access control list in the exported DSL.

    Options for child objects

    These options control how the hierarchy is stored in the file structure.

    Include All Child Objects

    Select to include all child objects in the top-level object hierarchy specified by <object name>.

    If not selected, the Child Object Types to Include box opens. Enter a comma-separated list of child object types to include.

    Use the describeObjectTypeStructure command to get a list of the hierarchy for a given top-level object type. Browse the hierarchy for the child object of interest and use its objectType.collectionName as the value to include in the comma-separated list.

    Example: pipelines,releases,applications

    Include all Child Objects in a Single DSL File

    Select to include all child objects into a single DSL file.

    If not selected, the Child Object Types to Export to Separate DSL files box opens. Enter a comma-separated list of child object types.

    • Wildcard characters are accepted.

    • Qualify the object as needed to uniquely specify it.

    Example: pipelines,procedures.*,applications.applicationTiers.components

    See Specifying child object lists for more details about specifying lists.

  3. Select Export to initiate the DSL export. The DSL file is downloaded into a file on your local system.

  4. Commit this version of the DSL file into your source code repository.

    This DSL file has all the details of the pipeline stages, gates, and tasks. It also retains references to the snapshots used for deployments in various stages of this pipeline.

Snapshots capture references to the exact versions of the artifacts, configurations, and so on. This lets you recreate the exact state of the pipeline at any point in the future for various scenarios. To recreate a pipeline, you check out that DSL file and evaluate the DSL using either the evalDsl API or the DSL editor. Evaluating this DSL recreates the pipeline as it was when the DSL file was created.

While this example showcases pipeline objects, the DSL export functionality is available from most CloudBees CD/RO objects.

This method is limited to the following object types: Applications, microservices, environments, master components, environment and resource templates, reports, releases, and pipelines.

Via API

Use the ectool generateDsl <path> [optionals] API command to generate an XML file representing the contents of a CloudBees CD/RO object. See the generateDsl command for full syntax and examples.

Object Hierarchy

Via UI

To generate DSL scripts representing the contents of an entire CloudBees CD/RO object structure including all nested objects, parameters, and custom properties, use the export DSL catalog item available with the CloudBees CD/RO UI. This method is available for all CloudBees CD/RO object types.

The scripts are organized in a file structure suitable for importing back into the object structure. In this way, you can use the corresponding Import DSL service catalog item to easily create new objects based on the existing object structure or to override the original object structure.