How-to: Export and import elements with YAML configuration

The following example task describes how to export and import elements with YAML configuration.

Before you begin

This example follows the steps in the Create a simple helloWorld deployment tutorial. Review the tutorial before you attempt to follow this example. Configure your system as described in Configure the helloWorld tutorial system.

About this task

In this example, you export components in YAML format, configure, and import them to other HCL DevOps Deploy (Deploy)systems. However, you can export other elements such as applications, application templates, components, component templates, processes, and so on.

Exporting or importing of elements in YAML format is the same as in JSON format. The difference is that you need to specify appropriate headers in the REST calls. For APIs that take input, like import or save actions, you must add the following header: Accept: application/yaml. For APIs that produce output, like export and get actions, you must add the following header: Content-Type: application/yaml.

Note:
  • If you don't use the headers, the elements are exported or imported in JSON format by default.
  • Exporting and importing snapshots with YAML is not supported.

Procedure

  1. Export the helloWorld component you created in Lesson 1 Create the helloWorld component by using the REST command. See Export a component to a json file. for command reference.
    While entering the REST command, ensure that you use the following header with your request:
    Content-Type: application/yaml
    The command returns a result similar to the following YAML definition:
    ---
    name: "helloWorld"
    description: ""
    created: 1700804083300
    componentType: "STANDARD"
    ignoreQualifiers: 0
    importAutomatically: false
    useVfs: true
    active: true
    deleted: false
    defaultVersionType: "FULL"
    cleanupDaysToKeep: 0
    cleanupCountToKeep: 0
    sourceConfigPluginName: "File System (Versioned)"
    envPropDefs: []
    resPropDefs: []
    versionPropDefs: []
    propSheetGroup:
        propSheets:
            - name: "template"
              properties: []
            - name: "custom"
              properties:
                  - name: "helloHome"
                    value: "C:\\Users\\Administrator\\Downloads\\helloWorld"
                    description: ""
                    secure: false
            - name: "FileSystemVersionedComponentProperties"
              properties:
                  - name: "saveFileExecuteBits"
                    value: "false"
                    description: ""
                    secure: false
                  - name: "extensions"
                    description: ""
                    secure: false
                  - name: "includes"
                    description: ""
                    secure: false
                  - name: "excludes"
                    description: ""
                    secure: false
                  - name: "basePath"
                    value: "C:\\Users\\Administrator\\Downloads\\helloWorld"
                    description: ""
                    secure: false
    processes:
        - name: "helloProcess"
          description: ""
          defaultWorkingDir: "${p:resource/work.dir}/${p:component.name}"
          takesVersion: true
          inventoryActionType: "ADD"
          status: "Active"
          configActionType: "ADD"
          active: true
          path: "components/18bffd2b-e64b-6d96-3016-4d13b84617e1/processes/18bffd9b-473b-6bc9-4e90-ad03192b1cf4"
          deleted: false
          propDefs: []
          rootActivity:
              edges:
                  - to: "Download Artifacts"
                    from: "Clean work space"
                    type: "SUCCESS"
                    value: ""
                  - to: "Clean work space"
                    type: "ALWAYS"
                    value: ""
                  - to: "Deploy artifacts"
                    from: "Compress artifacts"
                    type: "SUCCESS"
                    value: ""
                  - to: "069538fb309ede5cd10eaf7c7c81e3"
                    from: "Deploy artifacts"
                    type: "SUCCESS"
                    value: ""
                  - to: "Compress artifacts"
                    from: "Download Artifacts"
                    type: "SUCCESS"
                    value: ""
              offsets:
                  - name: "Download Artifacts"
                    x: -145
                    "y": 310
                    h: 110
                    w: 440
                  - name: "069538fb309ede5cd10eaf7c7c81e3"
                    x: -5
                    "y": 790
                    h: 100
                    w: 160
                  - name: "Deploy artifacts"
                    x: -120
                    "y": 630
                    h: 110
                    w: 390
                  - name: "Clean work space"
                    x: -205
                    "y": 150
                    h: 110
                    w: 560
                  - name: "Compress artifacts"
                    x: -120
                    "y": 470
                    h: 110
                    w: 390
              layoutMode: "auto"
              type: "graph"
              name: "83dd413d-d8d6-4c45-8458-bc7f2e976a5e"
              children:
                  - type: "finish"
                    name: "069538fb309ede5cd10eaf7c7c81e3"
                    children: []
                  - allowFailure: false
                    useImpersonation: false
                    showHidden: false
                    impersonationUseSudo: false
                    pluginVersion: 96
                    commandName: "Delete Files and Directories"
                    pluginName: "File Utils"
                    pluginId: "com.urbancode.air.plugin.FileUtils"
                    authTokenRestriction: "20000001-0001-0001-0001-000000000000"
                    properties:
                        baseDir: "."
                        includes: "*"
                        excludes: ""
                        followSymlinks: "false"
                        caseSensitive: "true"
                    cachedAuthTokenRestriction:
                        name: "System Default"
                        description:
                            "Used by default for any plugin steps without a specified token\
                            \ restriction"
                        restrictions:
                            - verb: "ALL"
                              url: "/*"
                    type: "plugin"
                    name: "Clean work space"
                    children: []
                  - allowFailure: false
                    useImpersonation: false
                    showHidden: false
                    impersonationUseSudo: false
                    pluginVersion: 46
                    commandName: "Download Artifacts"
                    pluginName: "UrbanCode Deploy Versioned File Storage"
                    pluginId: "com.urbancode.plugin.VFS"
                    authTokenRestriction: "20000001-0001-0001-0001-000000000000"
                    properties:
                        directoryOffset: "."
                        artifactSetBaseDir: ""
                        fileIncludePatterns: "**/*"
                        fileExcludePatterns: ""
                        syncMode: "true"
                        handleIncrementalVersions: "false"
                        fullVerification: "true"
                        setFileExecuteBits: "false"
                        verifyFileIntegrity: "false"
                        charset: ""
                        versionId: "${p:version.id}"
                        versionType: "${p:version.type}"
                        serverUrl: "${p:server.url}"
                        compId: "${p:component.id}"
                        resId: "${p:resource.id}"
                        envId: "${p:environment.id}"
                        maxMemory: "1G"
                        label: ""
                    cachedAuthTokenRestriction:
                        name: "System Default"
                        description:
                            "Used by default for any plugin steps without a specified token\
                            \ restriction"
                        restrictions:
                            - verb: "ALL"
                              url: "/*"
                    type: "plugin"
                    name: "Download Artifacts"
                    children: []
                  - allowFailure: false
                    useImpersonation: false
                    showHidden: false
                    impersonationUseSudo: false
                    pluginVersion: 96
                    commandName: "Create .zip File"
                    pluginName: "File Utils"
                    pluginId: "com.urbancode.air.plugin.FileUtils"
                    authTokenRestriction: "20000001-0001-0001-0001-000000000000"
                    properties:
                        zipName: "helloWorld.zip"
                        baseDir: "."
                        includes: "*"
                        excludes: ""
                        update: "false"
                        followSymlinks: "false"
                        caseSensitive: "true"
                        customEncoding: ""
                    cachedAuthTokenRestriction:
                        name: "System Default"
                        description:
                            "Used by default for any plugin steps without a specified token\
                            \ restriction"
                        restrictions:
                            - verb: "ALL"
                              url: "/*"
                    type: "plugin"
                    name: "Compress artifacts"
                    children: []
                  - allowFailure: false
                    useImpersonation: false
                    showHidden: false
                    impersonationUseSudo: false
                    pluginVersion: 96
                    commandName: "Move Directory"
                    pluginName: "File Utils"
                    pluginId: "com.urbancode.air.plugin.FileUtils"
                    authTokenRestriction: "20000001-0001-0001-0001-000000000000"
                    properties:
                        sourceDir: "."
                        destDir: "${p:helloHome}/target"
                        includes: "*.zip"
                        excludes: ""
                        mapperRules: ""
                    cachedAuthTokenRestriction:
                        name: "System Default"
                        description:
                            "Used by default for any plugin steps without a specified token\
                            \ restriction"
                        restrictions:
                            - verb: "ALL"
                              url: "/*"
                    type: "plugin"
                    name: "Deploy artifacts"
                    children: []
    configTemplates: []
    genericProcesses: []
    teamMappings: []
    tags: []                
  2. Copy the content into a text editor and save it.
  3. Edit the YAML configuration to include the changes you require.
  4. Import the component in YAML format by using REST command to the destination Deploy server.
    See Import component from json file. for command reference. You must use the following header with the REST call.
    Accept: application/yaml

Results

The file is imported and the record is displayed in the Components list.