---
sourceDocument: Australia IT Service Management
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/it-service-management

 Release :

    - australia

ft:locale :

    - en-US

ft:publication_title :

    - Australia IT Service Management

ft:clusterId :

    - itsm

bundleId :

    - itsm

workflow :

    - Technology


---

# Jenkins pipeline actions

# Jenkins pipeline actions {#ariaid-title1}

Release version: Australia  
Updated March 12, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 14 minutes to read  
Use these actions in your Jenkins pipeline to interact with the DevOps Config data model.  
Important:  
Starting with the Washington D.C. release, DevOps Config is being prepared for future deprecation. It will be hidden and no longer activated on new instances but will continue to be supported.

Jenkins scripted and declarative piplines are supported.  
These actions are provided to create a specific pipeline definition to achieve your goal. Add a command to your Jenkins file to perform these actions.

* snDevOpsConfigCombined action to upload, validate, and publish config data.

* snDevOpsConfigUploadUpload config data to DevOps Config via Agent
  Job.

* snDevOpsConfigGetSnapshotsRetrieve snapshots for a specific deployable, or all impacted
  deployables.

* snDevOpsConfigPublishPublish a snapshot for the given application and
  deployable.

* snDevOpsConfigExportExport a snapshot for a given application and deployable.

* snDevOpsConfigRegisterPipelineTie a changeset and/or snapshot to a pipeline execution.

* snDevOpsConfigValidateValidate config data against your organization policies.

* snDevOpsChangeCreate a change request with associated snapshot attached.

{#devops-config-jenkins-integration__ul_fp5_1qf_psb}

## snDevOpsConfig {#devops-config-jenkins-integration__section_iml_cxp_cyb}

Upload, validate, and publish config data changes in one step.

This action combines snDevOpsConfigUpload, snDevOpsConfigGetSnapshots, and snDevOpsConfigRegisterPipeline actions into one action, rather than having to execute each action separately.

Input variables
:

    |-|-|
    | configFile | Specifies the configuration data file to upload to the component or deployable path in the data model. |
    | applicationName | Specifies the application to where config data will be uploaded. |
    | target | Specifies the data model target to where config data will be uploaded (for example, <kbd class="ph userinput">component</kbd>, <kbd class="ph userinput">collection</kbd>, <kbd class="ph userinput">deployable</kbd>). |
    | collectionName | (Optional) Name of the collection to upload to (required if target is collection). |
    | deployableName | (Optional) Name of the deployable to upload to (required if target is deployable). |
    | namePath | Specifies the name path in the data model to where config data will be uploaded. Note: When uploading to a vars folder, you must start the name path with "vars/" to specifiy the variable folder path. |
    | dataFormat | Specifies the data format of the config file (for example, <kbd class="ph userinput">JSON</kbd>, <kbd class="ph userinput">YAML</kbd>, <kbd class="ph userinput">XML</kbd>, etc.) |
    | autoCommit | Specifies whether to commit configuration data after upload (true/false). Default is true. |
    | autoValidate | Specifies whether to validate configuration data during commit (true/false). Default is true. |
    | autoPublish | Specifies whether to publish the configuration data after validation (true/false). Default is true. |
    | changesetNumber | (Optional) Specifies the (open) changeset to which this upload activity is associated. If not provided, a new changeset is created. Note: Only used for multiple upload scenarios. |
    | markFailed | (Optional) Fail the pipeline in the event that the validation attempt failed (due to a backend issue). |
    | showResults | (Optional) Show validation results in the Jenkins job console log. |
    | continueWithLatest | (Optional) Specifies whether to return the latest snapshot per the <kbd class="ph userinput">applicatioName</kbd>-<kbd class="ph userinput">deployableName</kbd>-<kbd class="ph userinput">changesetNumber</kbd> combination if no snapshots are generated (true/false). Default is false. |
    [ ]

    {#devops-config-jenkins-integration__table_mqp_lxp_cyb}

Output
:
    * If successful, a snapshot or set of snapshots.
    * If failure, an API/backend failure message is shown.
    {#devops-config-jenkins-integration__ul_gxy_sxh_2yb}

Example
:
    * Input:  


          snapshotObj = snDevOpsConfig(
               applicationName: "PaymentDemo",
               configFile: "config/application/Collection/Collection2/*.json",
               target: "collection",
               collectionName: "release-1.0",
               namePath: "settings/infrastructure/database",
               dataFormat: "json",
               autoCommit: 'true',
               autoValidate: 'true',
               autoPublish: 'true',
               continueWithLatest: 'true',
               markFailed: 'true',
               showResults: 'false'
          )

          echo"*************************\n ${snapshotObj}"

    * Output
    {#devops-config-jenkins-integration__ul_hlr_2y5_2yb}

Example - collection
:   Note:  
    When uploading to a collection, the <kbd class="ph userinput">collectionName</kbd> argument is required.


        snDevOpsConfig(
             applicationName: 'PaymentDemo',
             target: 'collection',
             collectionName: 'release-1.0',
             namePath: 'web-api-v1.0',
             configFile: 'k8s/helm/*.yml',
             dataFormat: 'yaml',
             autoCommit: 'true',
             autoValidate: 'true',
             autoPublish: 'true'
        )

Example - deployable
:   Note:  
    When uploading to a deployable, the <kbd class="ph userinput">deployableName</kbd> argument is required.


        snDevOpsConfig(
             applicationName: 'PaymentDemo',
             target: 'deployable',
             deployableName: 'Production',
             namePath: 'web-api-v1.0',
             configFile: 'k8s/helm/*.yml',
             dataFormat: 'yaml',
             autoCommit: 'true',
             autoValidate: 'true',
             autoPublish: 'true'
        )

Multiple uploads in one commit

:   To upload configuration data from different locations, or to upload a set of data to multiple targets (for example, one component, one deployable) tracked as a single commit to your data model, you can call the
    <kbd class="ph userinput">snDevOpsConfigUpload</kbd> action as many times as necessary for the first set of uploads, then call the <kbd class="ph userinput">snDevOpsConfig</kbd> action for the final upload.​

    Here's an example.  
    * In the first upload, create a variable (for example, $changeset), and assign the return value of the step to it so it can be reused in subsequent uploads​.

      Upload 1 - XML file to component:


          $changeset = snDevOpsConfigUpload(
               applicationName: 'PaymentDemo',
               target: 'component',
               namePath: 'paymentService-v1.0',
               configFile: 'infra/v1/config.xml',
               dataFormat: 'xml',
               autoCommit: 'false',
               autoValidate: 'false',
               autoPublish: 'false'
          )

    * In subsequent uploads (and final upload), use the variable as an input​.

      Upload 2 - JSON file to vars folder of deployable:


          snDevOpsConfig(
               applicationName: 'PaymentDemo',
               target: 'deployable',
               deployableName: 'Production',
               namePath: 'vars/dbSettings',
               configFile: 'infra/prod/dbConfig.json',
               dataFormat: 'json',
               changesetNumber: "${changeset}",
               autoCommit: 'false',
               autoValidate: 'false',
               autoPublish: 'false',
               continueWithLatest: 'true'
          )

    {#devops-config-jenkins-integration__ul_urp_fzh_2yb}

Upload multiple data formats
:   To upload configuration data in different file formats, you can call the <kbd class="ph userinput">snDevOpsConfig</kbd> action with these specifications.

    * Ensure the <kbd class="ph userinput">configFile</kbd> argument is using a wildcard in the path.
    * Do not specify the <kbd class="ph userinput">dataFormat</kbd> argument.
    {#devops-config-jenkins-integration__ul_zbp_1zg_2zb}

    Here's an example.

    * Let's say we have these config files.

    * This is how to upload the config files using <kbd class="ph userinput">snDevOpsConfig</kbd>.  


          snDevOpsConfig(
               applicationName: 'PaymentDemo',
               target: 'component',
               namePath: 'paymentService-v1.0',
               configFile: 'infra/v1/*',
               autoCommit: 'true',
               autoValidate: 'true',
               autoPublish: 'true'
          )

    {#devops-config-jenkins-integration__ul_lnt_xxg_2zb}

## snDevOpsConfigUpload {#devops-config-jenkins-integration__section_f12_1lb_ypb}

This action uploads a configuration file to a given location within an application data
model.

It is meant to be used in an iterative nature for all config files to upload to the
application data model during the pipeline run.  
Supports:

* Upload to:
  * A component, collection, or deployable.
  * The variable (vars) folder of a component, collection, or deployable.
  {#devops-config-jenkins-integration__ul_wwn_5tk_dwb}
* Regex pattern for config file input.
* Ability to be called multiple times in the same pipeline.
{#devops-config-jenkins-integration__ul_bph_ysg_hvb}

Input variables
:

    |-|-|
    | configFile | Specifies the configuration data file to upload to the component or deployable path in the data model. |
    | applicationName | Specifies the application to where config data will be uploaded. |
    | target | Specifies the data model target to where config data will be uploaded (for example, <kbd class="ph userinput">component</kbd>, <kbd class="ph userinput">collection</kbd>, <kbd class="ph userinput">deployable</kbd>). |
    | collectionName | (Optional) Name of the collection to upload to (required if target is collection). |
    | deployableName | Name of the deployable to upload to (required if target is deployable). |
    | namePath | Specifies the name path in the data model to where config data will be uploaded. Note: When uploading to a vars folder, you must start the name path with "vars/" to specifiy the variable folder path. |
    | dataFormat | Specifies the data format of the config file (for example, <kbd class="ph userinput">JSON</kbd>, <kbd class="ph userinput">YAML</kbd>, <kbd class="ph userinput">XML</kbd>, etc.) |
    | convertPath | (Optional) Specifies whether to preserve the directory structure of configuration files (with respect to the workspace) and convert the directory to paths within the data model. |
    | changesetNumber | (Optional) Specifies the (open) changeset to which this upload activity is associated. If not provided, a new changeset is created. Note: Only used for multiple upload scenarios. |
    | autoCommit | Specifies whether to commit configuration data after upload (true/false). Default is false. |
    | autoValidate | Specifies whether to validate configuration data during commit (true/false). Default is false. |
    [ ]

    {#devops-config-jenkins-integration__table_ct3_qqf_psb}

Output variable
:

    |-|-|
    | changesetNumber | (Optional) Specifies the (open) changeset to which this upload activity is associated. If a changeset number is not provided, a new changeset is created. |
    [ ]

    {#devops-config-jenkins-integration__table_iz5_2ng_hvb}

Example
:
    * Input:Here is an example of the <kbd class="ph userinput">snDevOpsConfigUpload</kbd> action. For the sake of illustration, we'll assign the response to a variable, <kbd class="ph userinput">changeSetId</kbd>, which could be
      echoed out to our console log for debugging scenarios.


          changeSetId = snDevOpsConfigUpload(
               applicationName: "PaymentDemo",
               target: 'component',
               namePath: "web-api-v1.0",
               configFile: "k8s/helm/values.yml",
               dataFormat: "json",
               autoCommit: 'true',
               autoValidate: 'true'
          )

          echo "Changeset: $changeSetId created"

    * Output:In addition to the data being uploaded to our data model in DevOps Config, the output would look something like this (using the Blue Ocean plugin to visualize the console output).

    {#devops-config-jenkins-integration__ul_tqb_n4l_yxb}

Example - Multiple uploads (component)
:   You can call the upload action more than once to upload configuration data in different file formats from different locations, while still keeping the uploads part of one changeset.

    * In the first upload, name the action so the changesetNumber output variable can be reused in subsequent uploads.  
      YAML file upload:


          $changeset = snDevOpsConfigUpload(
               applicationName: 'PaymentDemo',
               target: 'component',
               namePath: 'wep-api-v1.0',
               configFile: 'k8s/helm/values.yml',
               dataFormat: 'yaml',
               autoCommit: 'false',
               autoValidate: 'false'
          )

    * In subsequent uploads, reference the changesetNumber output variable from the first upload as an input variable.  
      3 JSON files upload:


          snDevOpsConfigUpload(
               applicationName: 'PaymentDemo',
               target: 'component',
               namePath: 'wep-api-v1.0',
               configFile: 'infra/*.json',
               dataFormat: 'json',
               autoCommit: 'false',
               autoValidate: 'false',
               changesetNumber: "${changeset}"
          )

    * In the final call, in addition to referencing the changesetNumber output variable from the first upload as an input variable, set autoCommit and autoValidate to <kbd class="ph userinput">true</kbd>.  
      INI file upload:


          snDevOpsConfigUpload(
               applicationName: 'PaymentDemo',
               target: 'component',
               namePath: 'wep-api-v1.0',
               configFile: 'featureToggles/set1.ini',
               dataFormat: 'ini',
               autoCommit: 'true',
               autoValidate: 'true',
               changesetNumber: "${changeset}"
          )

    {#devops-config-jenkins-integration__ul_hwg_rng_hvb}

Example - Multiple uploads (collection and vars)
:   You can call the upload action more than once to upload configuration data in different file formats from different locations, while still keeping the uploads part of one changeset.

    * In the first upload, create a variable (for example, $changeset), and assign the return value of the step to it so it can be reused in subsequent uploads.  
      XML file upload:


          $changeset = snDevOpsConfigUpload(
               applicationName: 'PaymentDemo',
               target: 'collection',
               collectionName: 'release-v1.0',
               namePath: 'v1-common-configs',
               configFile: 'infra/v1/config.xml',
               dataFormat: 'xml',
               autoCommit: 'false',
               autoValidate: 'false'
          )

    * In subsequent uploads, use the variable as an input.  
      JSON file upload:


          snDevOpsConfigUpload(
               applicationName: 'PaymentDemo',
               target: 'deployable',
               deployableName: 'Production',
               namePath: 'vars/dbSettings',
               configFile: 'infra/prod/dbConfig.json',
               dataFormat: 'json',
               autoCommit: 'true',
               autoValidate: 'true',
               changesetNumber: "${changeset}"
          )

    {#devops-config-jenkins-integration__ul_ofk_4qm_dwb}

    Note:  
    To upload to a variable folder, uploadTarget must be set to <kbd class="ph userinput">deployable</kbd>, and the correct values must be set for deployableName and changesetNumber.

## snDevOpsConfigGetSnapshots {#devops-config-jenkins-integration__section_ics_2rf_psb}

This action is intended to be used in different scenarios:

* Retrieve all snapshots for any impacted deployables.When config files are uploaded to an
  application data model, the system will create snapshots for any deployables determined to be
  impacted by the upload. Following along the CI flow, assuming the last Upload call had
  validation enabled, the next step would be to iterate through the list of snapshots and ensure
  they all passed validation.

* Retrieve a specific snapshot.Following the CD flow, a specific snapshot is retrieved so it can be published and then exported to be consumed downstream (for example, to provision out infrastructure or
  application).

* Retrieve the latest snapshots for a deployable of an application in the event an upload does not generate any snapshots.A set of config data is available to deploy to an environment for an
  application-deployable-changeset combination when no configuration changes are made.

* Show policy validation results in a pipeline execution.View policy validation results as test results on the Jenkins build tests results page, including compliant with exception, when getting a snapshot.

{#devops-config-jenkins-integration__ul_lgc_ry2_psb}

Input definitions
:

    |-|-|
    | applicationName | Specifies the application to upload config data to or export data from. |
    | deployableName | (Optional) Specifies the deployable for the application on which to get the latest snapshot data. |
    | changesetNumber | (Optional) Specifies the changeset ID for the set of config changes the user is interested in. |
    | isValidated | (Optional) Specifies whether to return only snapshots that are passed, or passed with exception (true/false). Default is true. |
    | continueWithLatest | (Optional) Specifies whether to return the latest snapshot per the <kbd class="ph userinput">applicatioName</kbd>-<kbd class="ph userinput">deployableName</kbd>-<kbd class="ph userinput">changesetNumber</kbd> combination if no snapshots are generated (true/false). Default is false. |
    [ ]

    {#devops-config-jenkins-integration__table_hmn_3rf_psb}

Output
:
    * If successful, a snapshot or set of snapshots.
    * If failure, an API/backend failure message is shown.
    {#devops-config-jenkins-integration__ul_xhh_jqg_hvb}

Example
:
    * Specific snapshot (specified):  


          $snapshots = snDevOpsConfigGetSnapshots(
               applicationName: 'PaymentDemo',
               deployableName: 'Production',
               changesetNumber: 'Chset-16',
               isValidated: 'true',
               continueWithLatest: 'true'
          )

    * Latest validated snapshot (returns the latest snapshot for application and deployable combination):  


          $snapshots = snDevOpsConfigGetSnapshots(
               applicationName: 'PaymentDemo',
               deployableName: 'Production',
               isValidated: 'true'
          )

    * All changeset snapshots (returns all snapshots for application and deployable combination):  


          $snapshots = snDevOpsConfigGetSnapshots(
               applicationName: 'PaymentDemo',
               changesetNumber: 'Chset-16'
          )

    * Show policy validation results in a pipeline execution.  
      1. Assign a variable to the path of the file that contains the snapshot validation results generated during the <kbd class="ph userinput">snDevOpsConfigGetSnapshots</kbd> action.
      2. Call the [JUnit action](https://plugins.jenkins.io/junit/) to load the snapshot validation results into the pipeline execution test section.

      {#devops-config-jenkins-integration__ol_zkz_gyz_mwb}


          stage('Validate') {
              steps {
          	script {
                     changeSetResults = snDevOpsConfigGetSnapshots( ... )
                     if (!changeSetResults) {
                        echo "No snapshots were created"
                     } else {
          	       def changeSetResultsObject = readJSON text: changeSetResults

          	       changeSetResultsObject.each {
                            snapshotName = it.name
                            snapshotObject = it
          	       }
          	       // STEP 1
          		validationResultsPath = "${snapshotName}_${currentBuild.projectName}_${currentBuild.number}.xml"
          	    }
          	}
              }
          }

          post {
              always {
                  // STEP 2
                  junit testResults: "${validationResultsPath}", skipPublishingChecks: true
              }
          }

    {#devops-config-jenkins-integration__ul_v33_4qg_hvb}

## snDevOpsConfigPublish {#devops-config-jenkins-integration__section_mpv_lrf_psb}

This action publishes a snapshot for the given application and deployable. From here, the
snapshot can be consumed through the Export process.

Input definitions
:

    |-|-|
    | applicationName | Specifies the application from which to publish config data. |
    | deployableName | Specifies the deployable for the application from which to publish config data. |
    | snapshotName | Specifies the name of the snapshot to publish. |
    [ ]

    {#devops-config-jenkins-integration__table_i4g_xrf_psb}

Output
:
    * If successful, true.
    * Otherwise false.
    {#devops-config-jenkins-integration__ul_m4r_nrg_hvb}

Example
:


        snDevOpsConfigPublish(
             applicationName: 'PaymentDemo',
             deployableName: 'Production',
             snapshotName: 'Production-v23.dpl',
        )

## snDevOpsConfigExport {#devops-config-jenkins-integration__section_i3w_ksf_psb}

This action exports a snapshot for the given application and deployable.

The user should specify the exporter, relevant exporter arguments, the export format (for
example, YAML, JSON, etc.), and output location for the exported config data.

From here, the config data can be used directly as an input for a deployment or provisioning
tool downstream in the pipeline.

Input arguments
:

    |-|-|
    | applicationName | Specifies the application from which to export data. |
    | deployableName | Specifies the config deployable for the application from which to export data. |
    | snapshotName | (Optional) Specifies snapshot from which to export data. If a snapshot is not specified, the latest snapshot for the deployable is used. |
    | exporterName | Specifies the exporter to apply to the snapshot (for example, <kbd class="ph userinput">UniqueCDIs</kbd>). |
    | exporterArgs | (Optional) Specifies arguments to be used along with the exporter. |
    | exportFormat | Specifies the format to export the snapshot data (For example, <kbd class="ph userinput">INI</kbd>, <kbd class="ph userinput">YAML</kbd>, <kbd class="ph userinput">PROPS</kbd>). |
    | fileName | Specifies the file to export data to (assumed to be in the workspace). If a filename is not specified, a concatenation of application name and deployable name (plus file extension) is used by default. |
    [ ]

    {#devops-config-jenkins-integration__table_syy_nsf_psb}

Output
:
    * If successful, true.
    * Otherwise false.
    {#devops-config-jenkins-integration__ul_hfv_yrg_hvb}

Example
:


        snDevOpsConfigExport(
             applicationName: 'PaymentDemo',
             deployableName: 'Production',
             snapshotName: 'Production-v23.dpl',
             exporterFormat: 'yaml',
             exporterName: 'returnAllData-now',
             exporterArgs: '',
             fileName: 'exported_file-Production-20220302.yml'
        )

## snDevOpsConfigRegisterPipeline {#devops-config-jenkins-integration__section_c3m_vsf_psb}

This action ties a changeset and/or snapshot to the pipeline so that it can be tracked during
the pipeline execution. In DevOps Change Velocity, this is shown in the Pipeline
UI.

See [Accelerating your DevOps change process](https://servicenow-prod.fluidtopics.net/1IOGCXHTnX02RprvPaB2wg "Enable the change acceleration feature of DevOps Change Velocity for automatic change request creation in your pipeline, and use change approval flows and policies to automate approval under certain conditions.") for more
information regarding the DevOps Change Acceleration feature.

Input arguments
:

    |-|-|
    | applicationName | Specifies the name of the application. |
    | changesetNumber | (Optional) Specifies the changeset to associate with the pipeline execution. Note: Specify either changesetNumber or snapshotName, but not both. |
    | snapshotName | (Optional) Specifies the name of the snapshot to associate to the pipeline execution. Note: Specify either changesetNumber or snapshotName, but not both. |
    [ ]

    {#devops-config-jenkins-integration__table_uql_ctf_psb}

Output
:
    * If successful, true.
    * Otherwise false.
    {#devops-config-jenkins-integration__ul_urr_psg_hvb}

Example
:
    * Input:Here is an example of the <kbd class="ph userinput">snDevOpsConfigRegisterPipeline</kbd> action. For the sake of illustration, we'll assign the response to a variable,
      <kbd class="ph userinput">changeSetRegResult</kbd>, which could be echoed out to our console log for debugging scenarios.


          changeSetRegResult = snDevOpsConfigRegisterPipeline(
               applicationName: "PaymentDemo",
               changesetNumber: "Chset-122"
          )

          echo "Pipeline registration result: ${changeSetRegResult}"

    * Output:In addition to the data being uploaded to our data model in DevOps Config, the output would look something like this (using the Blue Ocean plugin to visualize the console output).

    {#devops-config-jenkins-integration__ul_cc2_knl_yxb}

## snDevOpsConfigValidate {#devops-config-jenkins-integration__section_rsc_wdj_psb}

Validate config data against your organization policies.

Input arguments
:

    |-|-|
    | applicationName | Application to validate. |
    | deployableName | Deployable for the application to validate. |
    | snapshotName | (Optional) Name of the snapshot to validate. |
    | markFailed | (Optional) Fail the pipeline in the event that the validation attempt failed (due to a backend issue). |
    | showResults | (Optional) Show validation results in the Jenkins job console log. |
    [ ]

    {#devops-config-jenkins-integration__table_e1d_zdj_psb}

Output
:
    * If successful, no output.
    * If failure, an API/backend failure message is shown.
    {#devops-config-jenkins-integration__ul_dcv_1pg_hvb}

Example
:
    * Specific snapshot (specified):  


          snDevOpsConfigValidate(
               applicationName: 'PaymentDemo',
               deployableName: 'Production',
               snapshotName: 'Production-v23.dpl',
          )

    * Latest snapshot (retrieves and validates the latest snapshot for application and deployable combination):  


          $changeset = snDevOpsConfigValidate(
               applicationName: 'PaymentDemo',
               deployableName: 'Production'
          )

    {#devops-config-jenkins-integration__ul_qgw_kpg_hvb}

## snDevOpsChange {#devops-config-jenkins-integration__section_zk1_w5x_mxb}

Create a change request and attach a snapshot for reference.

See [Accelerating your DevOps change process](https://servicenow-prod.fluidtopics.net/1IOGCXHTnX02RprvPaB2wg "Enable the change acceleration feature of DevOps Change Velocity for automatic change request creation in your pipeline, and use change approval flows and policies to automate approval under certain conditions.") for more information regarding the DevOps Change Acceleration feature.

Input arguments
:

    |-|-|
    | applicationName | Specifies the name of the application. |
    | snapshotName | Specifies the name of the snapshot to associate with the change request. |
    [ ]

    {#devops-config-jenkins-integration__table_w5k_x5x_mxb}

Example
:


        snDevOpsChange(
             applicationName: 'PaymentDemo',
             snapshotName: 'Production-v23.dpl'
        )

## Jenkins pipeline example {#devops-config-jenkins-integration__section_m1b_gvz_mwb}


    pipeline {
        environment {
            buildArtifactsPath = "build_artifacts/${currentBuild.number}"
            validationResultsPath = ""
        }

        agent any

        stages {
            // Initialize pipeline
            stage('Initialize') {
                steps {
                    script {
                        // DevOps Config application related information
                        appName = 'PaymentDemo'
                        deployableName = 'Production'
                        componentName = "web-api-v1.0"
                        collectionName = "release-1.0"
                        // Configuration file information
                        exportFormat = 'yaml'
                        configFilePath = "k8s/helm/values.yml"
                        // Exporter related information
                        exporterName = 'returnAllData-nowPreview' 
                        exporterArgs = ''
                        // Jenkins variables declared to be used in pipeline
                        exportFileName = "${buildArtifactsPath}/export_file-${appName}-${deployableName}-${currentBuild.number}.${exportFormat}"
                        changeSetId = ""
                        snapshotName = ""
                        snapshotObject = ""
                        isSnapshotValidateionRequired = false
                        isSnapshotPublisingRequired = false
                    }
                }
            }
                
            // Validate configuration data changes
            stage('Validate') {
                parallel {
                    stage('Config') {
                        stages('Config Steps') {
                            // Upload configuration data to DevOps Config
                            stage('Upload, Validate, & Publish') {
                                steps {
                                    sh "echo uploading and auto-validating configuration file: ${configFilePath}"
                                    script {
                                        changeSetResults = snDevOpsConfig(
                                            applicationName: "${appName}",
                                            target: 'component',
                                            namePath: "${componentName}",
                                            configFile: "${configFilePath}",
                                            dataFormat: "${configFileFormat}",
                                            autoCommit: 'true',
                                            autoValidate: 'true',
                                            autoPublish: 'true',
                                            isValidated: 'true',
                                            continueWithLatest: 'true',
                                            markFailed: 'true'
                                        )

                                        echo "Snapshots generated, validated, and published: ${changeSetResults}"

                                        def changeSetResultsObject = readJSON text: changeSetResults

                                        changeSetResultsObject.each {
                                            snapshotName = it.name
                                            snapshotObject = it
                                        }

                                        validationResultsPath = "${snapshotName}_${currentBuild.projectName}_${currentBuild.number}*.xml"
                                    }
                                }
                            }
                            // Export published snapshot to be used by downstream deployment tools
                            stage('Export') {
                                steps {
                                    script {
                                        // create build artifacts dir to store export file
                                        sh "mkdir -p ${buildArtifactsPath}"
                                        
                                        exportResponse = snDevOpsConfigExport(
                                            applicationName: "${appName}",
                                            snapshotName: "${snapshotObject.name}",
                                            deployableName: "${deployableName}",
                                            exporterFormat: "${exportFormat}",
                                            fileName: "${exportFileName}",
                                            exporterName: "${exporterName}",
                                            exporterArgs: "${exporterArgs}"
                                        )
                                    }
                                }
                            }
                        }
                    }
                }
            }
            
            // Create change request and attach snapshot for reference
            stage('Change Management') {
                steps {
                    script {
                        // Trigger change request
                        snDevOpsChange(
                            applicationName: "${appName}",
                            snapshotName: "${snapshotName}"
                        )
                    }     
                }
            }
        }
        // NOTE: attach snapshot validation results to run (if the snapshot fails validation)
        post {
            always {
                // attach policy validation results
                junit testResults: "${validationResultsPath}", skipPublishingChecks: true
            }
        }
    }


