diff --git a/src/com/mirantis/mk/Workflow.groovy b/src/com/mirantis/mk/Workflow.groovy
index 79456cf..c3f864d 100644
--- a/src/com/mirantis/mk/Workflow.groovy
+++ b/src/com/mirantis/mk/Workflow.groovy
@@ -25,14 +25,55 @@
  * @param global_variables  Map that keeps the artifact URLs and used 'env' objects:
  *                          {'PARAM1_NAME': <param1 value>, 'PARAM2_NAME': 'http://.../artifacts/param2_value', ...}
  */
-def printVariables(global_variables) {
-    def message = "// Collected global_variables during the workflow:\n"
-    for (variable in global_variables) {
-        message += "env.${variable.key}=\"\"\"${variable.value}\"\"\"\n"
+def printVariables(global_variables, Boolean yamlStyle = true) {
+    def common = new com.mirantis.mk.Common()
+    def mcpcommon = new com.mirantis.mcp.Common()
+    def global_variables_msg = ''
+    if (yamlStyle) {
+        global_variables_msg = mcpcommon.dumpYAML(global_variables)
+    } else {
+        for (variable in global_variables) {
+            global_variables_msg += "env.${variable.key}=\"\"\"${variable.value}\"\"\"\n"
+        }
     }
+    def message = "// Collected global_variables during the workflow:\n${global_variables_msg}"
     common.warningMsg(message)
 }
 
+
+/**
+ * Print stack trace to the console
+ */
+def printStackTrace(e, String prefix = 'at com.mirantis') {
+    def common = new com.mirantis.mk.Common()
+    StringWriter writer = new StringWriter()
+    e.printStackTrace(new PrintWriter(writer))
+    String stackTrace = writer
+
+    // Filter the stacktrace to show only the lines related to the specified library
+    String[] lines = stackTrace.split("\n")
+    String stackTraceFiltered = ''
+    Boolean filteredLine = false
+    for (String line in lines) {
+        if (line.contains('at ') && line.contains(prefix)) {
+            if (!filteredLine) {
+                stackTraceFiltered += "...\n"
+                filteredLine = true
+            }
+            stackTraceFiltered += "${line}\n"
+        }
+        else if (!line.contains('at ')) {
+            if (filteredLine) {
+                stackTraceFiltered += "...\n"
+                filteredLine = false
+            }
+            stackTraceFiltered += "${line}\n"
+        }
+    }
+    common.errorMsg("Stack trace:\n${stackTraceFiltered}")
+}
+
+
 /**
  * Get Jenkins parameter names, values and types from jobName
  * @param jobName job name
@@ -44,9 +85,10 @@
  */
 def getJobDefaultParameters(jobName) {
     def jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
-    def item = jenkinsUtils.getJobByName(env.JOB_NAME)
+    def item = jenkinsUtils.getJobByName(jobName)
     def parameters = [:]
-    def prop = item.getProperty(ParametersDefinitionProperty.class)
+    // def prop = item.getProperty(ParametersDefinitionProperty.class)
+    def prop = item.getProperty(ParametersDefinitionProperty)
     if (prop != null) {
         for (param in prop.getParameterDefinitions()) {
             def defaultParam = param.getDefaultParameterValue()
@@ -59,10 +101,10 @@
     return parameters
 }
 
+
 /**
- * Run a Jenkins job using the collected parameters
+ * Generate parameters for a Jenkins job using different sources
  *
- * @param job_name          Name of the running job
  * @param job_parameters    Map that declares which values from global_variables should be used, in the following format:
  *                          {'PARAM_NAME': {'type': <job parameter $class name>, 'use_variable': <a key from global_variables>}, ...}
  *                          or
@@ -72,15 +114,16 @@
  *                          or
  *                          {'PARAM_NAME': {'type': <job parameter $class name>, 'get_variable_from_yaml': {'yaml_url': <URL with YAML content>,
  *                                                                                                          'yaml_key': <a groovy-interpolating path to the key in the YAML, starting from dot '.'> } }, ...}
+ *                          or
+ *                          {'PARAM_NAME': {'type': <job parameter $class name>, 'use_variables_map': <a nested map of job_parameters>}, ...}
+ *                                         , where job_parameters may contain a special 'type': '_defaultText' for a Yaml with some additional parameters for this map
  * @param global_variables  Map that keeps the artifact URLs and used 'env' objects:
  *                          {'PARAM1_NAME': <param1 value>, 'PARAM2_NAME': 'http://.../artifacts/param2_value', ...}
- * @param propagate         Boolean. If false: allows to collect artifacts after job is finished, even with FAILURE status
- *                          If true: immediatelly fails the pipeline. DO NOT USE 'true' if you want to collect artifacts
- *                          for 'finally' steps
  */
-def runJob(job_name, job_parameters, global_variables, Boolean propagate = false) {
+def generateParameters(job_parameters, global_variables) {
     def parameters = []
     def common = new com.mirantis.mk.Common()
+    def mcpcommon = new com.mirantis.mcp.Common()
     def http = new com.mirantis.mk.Http()
     def engine = new groovy.text.GStringTemplateEngine()
     def template
@@ -88,6 +131,7 @@
     def base = [:]
     base["url"] = ''
     def variable_content
+    def env_variables = common.getEnvAsMap()
 
     // Collect required parameters from 'global_variables' or 'env'
     for (param in job_parameters) {
@@ -102,7 +146,9 @@
                 global_variables[param.value.get_variable_from_url] = env[param.value.get_variable_from_url] ?: ''
             }
             if (global_variables[param.value.get_variable_from_url]) {
-                variable_content = http.restGet(base, global_variables[param.value.get_variable_from_url]).trim()
+                variable_content = http.restGet(base, global_variables[param.value.get_variable_from_url])
+                // http.restGet() attempts to read the response as a JSON, and may return an object instead of a string
+                variable_content = "${variable_content}".trim()
                 parameters.add([$class: "${param.value.type}", name: "${param.key}", value: variable_content])
                 common.infoMsg("${param.key}: <${param.value.type}> ${variable_content}")
             } else {
@@ -115,21 +161,21 @@
                 if (!global_variables[yaml_url_var]) {
                     global_variables[yaml_url_var] = env[yaml_url_var] ?: ''
                 }
-                yaml_url = global_variables[yaml_url_var]  // Real YAML URL
-                yaml_key = param.value.get_variable_from_yaml.yaml_key
+                def yaml_url = global_variables[yaml_url_var]  // Real YAML URL
+                def yaml_key = param.value.get_variable_from_yaml.yaml_key
                 // Key to get the data from YAML, to interpolate in the groovy, for example:
                 //  <yaml_map_variable>.key.to.the[0].required.data , where yaml_key = '.key.to.the[0].required.data'
                 if (yaml_url) {
                     if (!yamls_from_urls[yaml_url]) {
                         common.infoMsg("Reading YAML from ${yaml_url} for ${param.key}")
-                        yaml_content = http.restGet(base, yaml_url)
+                        def yaml_content = http.restGet(base, yaml_url)
                         yamls_from_urls[yaml_url] = readYaml text: yaml_content
                     }
                     common.infoMsg("Getting key ${yaml_key} from YAML ${yaml_url} for ${param.key}")
-                    template_variables = [
-                      'yaml_data': yamls_from_urls[yaml_url]
+                    def template_variables = [
+                        'yaml_data': yamls_from_urls[yaml_url],
                     ]
-                    request = "\${yaml_data${yaml_key}}"
+                    def request = "\${yaml_data${yaml_key}}"
                     def result
                     // Catch errors related to wrong key or index in the list or map objects
                     // For wrong key in map or wrong index in list, groovy returns <null> object,
@@ -154,12 +200,45 @@
                 common.warningMsg("${param.key} missing 'yaml_url'/'yaml_key' parameters, skipping get_variable_from_yaml")
             }
         } else if (param.value.containsKey('use_template')) {
-            template = engine.createTemplate(param.value.use_template).make(global_variables)
+            template = engine.createTemplate(param.value.use_template.toString()).make(env_variables + global_variables)
             parameters.add([$class: "${param.value.type}", name: "${param.key}", value: template.toString()])
             common.infoMsg("${param.key}: <${param.value.type}>\n${template.toString()}")
+        } else if (param.value.containsKey('use_variables_map')) {
+              // Generate multistring YAML with key/value pairs (like job_parameters) from a nested parameters map
+              def nested_parameters = generateParameters(param.value.use_variables_map, global_variables)
+              def nested_values = [:]
+              for (_parameter in nested_parameters) {
+                  if (_parameter.$class == '_defaultText') {
+                      // This is a special type for multiline with default values
+                      def _values = readYaml(text: _parameter.value ?: '---') ?: [:]
+                      _values << nested_values
+                      nested_values = _values
+                  } else {
+                      nested_values[_parameter.name] = _parameter.value
+                  }
+              }
+              def multistring_value = mcpcommon.dumpYAML(nested_values)
+              parameters.add([$class: "${param.value.type}", name: "${param.key}", value: multistring_value])
+              common.infoMsg("${param.key}: <${param.value.type}>\n${multistring_value}")
         }
     }
+    return parameters
+}
 
+
+/**
+ * Run a Jenkins job using the collected parameters
+ *
+ * @param job_name          Name of the running job
+ * @param job_parameters    Map that declares which values from global_variables should be used
+ * @param global_variables  Map that keeps the artifact URLs and used 'env' objects
+ * @param propagate         Boolean. If false: allows to collect artifacts after job is finished, even with FAILURE status
+ *                          If true: immediatelly fails the pipeline. DO NOT USE 'true' if you want to collect artifacts
+ *                          for 'finally' steps
+ */
+def runJob(job_name, job_parameters, global_variables, Boolean propagate = false) {
+
+    def parameters = generateParameters(job_parameters, global_variables)
     // Build the job
     def job_info = build job: "${job_name}", parameters: parameters, propagate: propagate
     return job_info
@@ -176,15 +255,16 @@
      *                     'reindex-testing-core-release-index-with-rc'        : 2822
      *                     'si-test-release-sanity-check-prepare-configuration': 1877
      */
-    common = new com.mirantis.mk.Common()
+    def common = new com.mirantis.mk.Common()
     def jobsOverrides = readYaml(text: env.CI_JOBS_OVERRIDES ?: '---') ?: [:]
     // get id of overriding job
     def jobOverrideID = jobsOverrides.getOrDefault(fullTaskName, '')
     if (fullTaskName in jobsOverrides.keySet()) {
         common.warningMsg("Overriding: ${fullTaskName}/${job_name} <<< ${jobOverrideID}")
         common.infoMsg("For debug pin use:\n'${fullTaskName}' : ${jobOverrideID}")
-        return Jenkins.instance.getItemByFullName(job_name,
-          hudson.model.Job.class).getBuildByNumber(jobOverrideID.toInteger())
+        // return Jenkins.instance.getItemByFullName(job_name,
+        //    hudson.model.Job.class).getBuildByNumber(jobOverrideID.toInteger())
+        return Jenkins.instance.getItemByFullName(job_name, hudson.model.Job).getBuildByNumber(jobOverrideID.toInteger())
     } else {
         return runJob(job_name, job_parameters, global_variables, propagate)
     }
@@ -209,7 +289,7 @@
     def common = new com.mirantis.mk.Common()
     def http = new com.mirantis.mk.Http()
     def artifactory = new com.mirantis.mcp.MCPArtifactory()
-    if(!artifactory_url && !artifactory_server) {
+    if (!artifactory_url && !artifactory_server) {
         artifactory_url = 'https://artifactory.mcp.mirantis.net/artifactory/api/storage/si-local/jenkins-job-artifacts'
     } else if (!artifactory_url && artifactory_server) {
         artifactory_url = artifactory.getArtifactoryServer(artifactory_server).getUrl() + '/artifactory/api/storage/si-local/jenkins-job-artifacts'
@@ -251,62 +331,145 @@
     }
 }
 
+
+def getStatusStyle(status) {
+    // Styling the status of job result
+    def status_style = ''
+    switch (status) {
+        case "SUCCESS":
+            status_style = "<td style='color: green;'><img src='/images/16x16/blue.png' alt='SUCCESS'>"
+            break
+        case "UNSTABLE":
+            status_style = "<td style='color: #FF5733;'><img src='/images/16x16/yellow.png' alt='UNSTABLE'>"
+            break
+        case "ABORTED":
+            status_style = "<td style='color: red;'><img src='/images/16x16/aborted.png' alt='ABORTED'>"
+            break
+        case "NOT_BUILT":
+            status_style = "<td style='color: red;'><img src='/images/16x16/aborted.png' alt='NOT_BUILT'>"
+            break
+        case "FAILURE":
+            status_style = "<td style='color: red;'><img src='/images/16x16/red.png' alt='FAILURE'>"
+            break
+        default:
+            status_style = "<td>-"
+    }
+    return status_style
+}
+
+
+def getTrStyle(jobdata) {
+    def trstyle = "<tr>"
+    // Grey background for 'finally' jobs in list
+    if (jobdata.getOrDefault('type', '') == 'finally') {
+        trstyle = "<tr style='background: #DDDDDD;'>"
+    }
+    return trstyle
+}
+
+
 /**
- * Update workflow job build description
+ * Update a 'job' step description
  *
- * @param jobs_data               Map with all job names and result statuses, to showing it in description
+ * @param jobsdata               Map with a 'job' step details and status
  */
-def updateDescription(jobs_data) {
-    def common = new com.mirantis.mk.Common()
-    def table = ''
-    def child_jobs_description = '<strong>Descriptions from jobs:</strong><br>'
-    def table_template_start = "<div><table style='border: solid 1px;'><tr><th>Job:</th><th>Duration:</th><th>Status:</th></tr>"
-    def table_template_end = "</table></div>"
+def getJobDescription(jobdata) {
+    def trstyle = getTrStyle(jobdata)
+    def display_name = jobdata['desc'] ? "${jobdata['desc']}: ${jobdata['build_id']}" : "${jobdata['name']}: ${jobdata['build_id']}"
+    if ((env.WF_SHOW_FULL_WORKFLOW_DESCRIPTION ?: false).toBoolean()) {
+        display_name = "[${jobdata['name']}/${jobdata['build_id']}]: ${jobdata['desc']}"
+    }
 
+    // Attach url for already built jobs
+    def build_url = display_name
+    if (jobdata['build_url'] != "0") {
+        build_url = "<a href=${jobdata['build_url']}>$display_name</a>"
+    }
+
+    def status_style = getStatusStyle(jobdata['status'].toString())
+
+    return [[trstyle, build_url, jobdata['duration'], status_style,],]
+}
+
+
+/**
+ * Update a 'script' step description
+ *
+ * @param jobsdata               Map with a 'script' step details and status
+ */
+def getScriptDescription(jobdata) {
+    def trstyle = getTrStyle(jobdata)
+
+    def display_name = "${jobdata['desc']}" ?: "${jobdata['name']}"
+    if ((env.WF_SHOW_FULL_WORKFLOW_DESCRIPTION ?: false).toBoolean()) {
+        display_name = "[${jobdata['name']}]: ${jobdata['desc']}"
+    }
+
+    // Attach url for already built jobs
+    def build_url = display_name
+    if (jobdata['build_url'] != "0") {
+        build_url = "<a href=${jobdata['build_url']}>$display_name</a>"
+    }
+
+    def status_style = getStatusStyle(jobdata['status'].toString())
+
+    return [[trstyle, build_url, jobdata['duration'], status_style,],]
+}
+
+
+/**
+ * Update a 'parallel' or a 'sequence' step description
+ *
+ * @param jobsdata               Map with a 'together' step details and statuses
+ */
+def getNestedDescription(jobdata) {
+    def tableEntries = []
+    def trstyle = getTrStyle(jobdata)
+
+    def display_name = "${jobdata['desc']}" ?: "${jobdata['name']}"
+    if ((env.WF_SHOW_FULL_WORKFLOW_DESCRIPTION ?: false).toBoolean()) {
+        display_name = "[${jobdata['name']}]: ${jobdata['desc']}"
+    }
+
+    // Attach url for already built jobs
+    def build_url = display_name
+    if (jobdata['build_url'] != "0") {
+        build_url = "<a href=${jobdata['build_url']}>$display_name</a>"
+    }
+
+    def status_style = getStatusStyle(jobdata['status'].toString())
+
+    tableEntries += [[trstyle, build_url, jobdata['duration'], status_style,],]
+
+    // Collect nested job descriptions
+    for (nested_jobdata in jobdata['nested_steps_data']) {
+        (nestedTableEntries, _) = getStepDescription(nested_jobdata.value)
+        for (nestedTableEntry in nestedTableEntries) {
+            (nested_trstyle, nested_display_name, nested_duration, nested_status_style) = nestedTableEntry
+            tableEntries += [[nested_trstyle, "&emsp;| ${nested_jobdata.key}: ${nested_display_name}", nested_duration, nested_status_style,],]
+        }
+    }
+    return tableEntries
+}
+
+
+def getStepDescription(jobs_data) {
+    def tableEntries = []
+    def child_jobs_description = ''
     for (jobdata in jobs_data) {
-        def trstyle = "<tr>"
-        // Grey background for 'finally' jobs in list
-        if (jobdata.getOrDefault('type', '') == 'finally') {
-            trstyle = "<tr style='background: #DDDDDD;'>"
-        }
-        // 'description' instead of job name if it exists
-        def display_name = "'${jobdata['name']}': ${jobdata['build_id']}"
-        if ((jobdata.getOrDefault('desc', '').toString() != '') && (jobdata.getOrDefault('desc', '').toString() != 'null')) {
-            display_name = "'${jobdata['desc']}': ${jobdata['build_id']}"
-        }
 
-        // Attach url for already built jobs
-        def build_url = display_name
-        if (jobdata['build_url'] != "0") {
-            build_url = "<a href=${jobdata['build_url']}>$display_name</a>"
+        if (jobdata['step_key'] == 'job') {
+            tableEntries += getJobDescription(jobdata)
         }
-
-        // Styling the status of job result
-        switch (jobdata['status'].toString()) {
-            case "SUCCESS":
-                status_style = "<td style='color: green;'><img src='/images/16x16/blue.png' alt='SUCCESS'>"
-                break
-            case "UNSTABLE":
-                status_style = "<td style='color: #FF5733;'><img src='/images/16x16/yellow.png' alt='UNSTABLE'>"
-                break
-            case "ABORTED":
-                status_style = "<td style='color: red;'><img src='/images/16x16/aborted.png' alt='ABORTED'>"
-                break
-            case "NOT_BUILT":
-                status_style = "<td style='color: red;'><img src='/images/16x16/aborted.png' alt='NOT_BUILT'>"
-                break
-            case "FAILURE":
-                status_style = "<td style='color: red;'><img src='/images/16x16/red.png' alt='FAILURE'>"
-                break
-            default:
-                status_style = "<td>-"
+        else if (jobdata['step_key'] == 'script') {
+            tableEntries += getScriptDescription(jobdata)
         }
-
-        // Collect table
-        table += "$trstyle<td>$build_url</td><td>${jobdata['duration']}</td>$status_style</td></tr>"
+        else if (jobdata['step_key'] == 'parallel' || jobdata['step_key'] == 'sequence') {
+            tableEntries += getNestedDescription(jobdata)
+        }
 
         // Collecting descriptions of builded child jobs
-        if (jobdata['child_desc'] != "") {
+        if (jobdata['child_desc'] != '') {
             child_jobs_description += "<b><small><a href=${jobdata['build_url']}>- ${jobdata['name']} (${jobdata['status']}):</a></small></b><br>"
             // remove "null" message-result from description, but leave XXX:JOBRESULT in description
             if (jobdata['child_desc'] != 'null') {
@@ -314,13 +477,39 @@
             }
         }
     }
+    return [tableEntries, child_jobs_description]
+}
+
+/**
+ * Update description for workflow steps
+ *
+ * @param jobs_data               Map with all step names and result statuses, to showing it in description
+ */
+def updateDescription(jobs_data) {
+    def child_jobs_description = '<strong>Descriptions from jobs:</strong><br>'
+    def table_template_start = "<div><table style='border: solid 1px;'><tr><th>Job:</th><th>Duration:</th><th>Status:</th></tr>"
+    def table_template_end = "</table></div>"
+
+    (tableEntries, _child_jobs_description) = getStepDescription(jobs_data)
+
+    def table = ''
+    for (tableEntry in tableEntries) {
+        // Collect table
+        (trstyle, display_name, duration, status_style) = tableEntry
+        table += "${trstyle}<td>${display_name}</td><td>${duration}</td>${status_style}</td></tr>"
+    }
+
+    child_jobs_description += _child_jobs_description
+
     currentBuild.description = table_template_start + table + table_template_end + child_jobs_description
 }
 
+
 def runStep(global_variables, step, Boolean propagate = false, artifactoryBaseUrl = '', artifactoryServer = '') {
     return {
         def common = new com.mirantis.mk.Common()
         def engine = new groovy.text.GStringTemplateEngine()
+        def env_variables = common.getEnvAsMap()
 
         String jobDescription = step['description'] ?: ''
         def jobName = step['job']
@@ -366,20 +555,24 @@
         // Collect job parameters and run the job
         // WARN(alexz): desc must not contain invalid chars for yaml
         def jobResult = runOrGetJob(jobName, jobParameters,
-                                   global_variables, propagate, jobDescription)
+                                    global_variables, propagate, jobDescription)
         def buildDuration = jobResult.durationString ?: '-'
         if (buildDuration.toString() == null) {
             buildDuration = '-'
         }
+        def desc = engine.createTemplate(jobDescription.toString()).make(env_variables + global_variables)
+        if ((desc.toString() == '') || (desc.toString() == 'null')) {
+            desc = ''
+        }
         def jobSummary = [
           job_result       : jobResult.getResult().toString(),
           build_url        : jobResult.getAbsoluteUrl().toString(),
           build_id         : jobResult.getId().toString(),
           buildDuration    : buildDuration,
-          desc             : engine.createTemplate(jobDescription).make(global_variables),
+          desc             : desc,
         ]
         def _buildDescription = jobResult.getDescription().toString()
-        if(_buildDescription){
+        if (_buildDescription) {
             jobSummary['build_description'] = _buildDescription
         }
         // Store links to the resulting artifacts into 'global_variables'
@@ -388,24 +581,328 @@
         return jobSummary
     }
 }
-/**
- * Run the workflow or final steps one by one
- *
- * @param steps                   List of steps (Jenkins jobs) to execute
- * @param global_variables        Map where the collected artifact URLs and 'env' objects are stored
- * @param failed_jobs             Map with failed job names and result statuses, to report it later
- * @param jobs_data               Map with all job names and result statuses, to showing it in description
- * @param step_id                 Counter for matching step ID with cell ID in description table
- * @param propagate               Boolean. If false: allows to collect artifacts after job is finished, even with FAILURE status
- *                                If true: immediately fails the pipeline. DO NOT USE 'true' with runScenario().
- */
-def runSteps(steps, global_variables, failed_jobs, jobs_data, step_id, Boolean propagate = false, artifactoryBaseUrl = '', artifactoryServer = '') {
-    common = new com.mirantis.mk.Common()
-    // Show expected jobs list in description
-    updateDescription(jobs_data)
 
-    for (step in steps) {
-        stage("Preparing for run job ${step['job']}") {
+
+def runScript(global_variables, step, artifactoryBaseUrl = '', artifactoryServer = '', scriptsLibrary = null) {
+    def common = new com.mirantis.mk.Common()
+    def env_variables = common.getEnvAsMap()
+
+    if (!scriptsLibrary) {
+        error "'scriptsLibrary' argument is not provided to load a script object '${step['script']}' from that library"
+    }
+    // Evaluate the object from it's name, for example: scriptsLibrary.com.mirantis.si.runtime_steps.ParallelMkeMoskUpgradeSequences
+    def scriptObj = scriptsLibrary
+    for (sObj in step['script'].split("\\.")) {
+        scriptObj = scriptObj."$sObj"
+    }
+
+    def script = scriptObj.new()
+
+    def scriptSummary = [
+      job_result       : '',
+      desc             : step['description'] ?: '',
+    ]
+
+    // prepare 'script_env' from merged 'env' and script step parameters
+    def script_env = env_variables.clone()
+    def stepParameters = step['parameters'] ?: [:]
+    def script_parameters = generateParameters(stepParameters, global_variables)
+    println "${script_parameters}"
+    for (script_parameter in script_parameters) {
+        common.infoMsg("Updating script env['${script_parameter.name}'] with value: ${script_parameter.value}")
+        script_env[script_parameter.name] = script_parameter.value
+    }
+
+    try {
+        script.main(this, script_env)
+        scriptSummary['script_result'] = 'SUCCESS'
+    } catch (InterruptedException e) {
+        scriptSummary['script_result'] = 'ABORTED'
+        printStackTrace(e)
+    } catch (e) {
+        scriptSummary['script_result'] = 'FAILURE'
+        printStackTrace(e)
+    }
+
+    // Store links to the resulting artifacts into 'global_variables'
+    storeArtifacts(env.BUILD_URL, step['artifacts'],
+                   global_variables, env.JOB_NAME, env.BUILD_NUMBER, artifactoryBaseUrl, artifactoryServer)
+
+    return scriptSummary
+}
+
+
+def runParallel(global_variables, step, failed_jobs, global_jobs_data, nested_steps_data, artifactoryBaseUrl = '', artifactoryServer = '', scriptsLibrary = null, prefixMsg = '') {
+    // Run the specified steps in parallel
+    // Repeat the steps for each parameters set from 'repeat_with_parameters_from_yaml'
+    // If 'repeat_with_parameters_from_yaml' is not provided, then 'parallel' step will perform just one iteration for a default "- _FOO: _BAR" parameter
+    // If 'repeat_with_parameters_from_yaml' is present, but the specified artifact contains empty list '[]', then 'parallel' step will be skipped
+    // Example:
+    // - parallel:
+    //     - job:
+    //     - job:
+    //     - sequence:
+    //   repeat_with_parameters_from_yaml:
+    //     type: TextParameterValue
+    //     get_variable_from_url: SI_PARALLEL_PARAMETERS
+    //   max_concurrent: 2               # how many parallel jobs shold be run at the same time
+    //   max_concurrent_interval: 300    # how many seconds should be passed between checking for an available concurrency
+    //   check_failed_concurrent: false  # stop waiting for available concurrent executors if count of failed jobs >= max_concurrent,
+    //                                   # which means that all available shared resources are occupied by the failed jobs
+    def common = new com.mirantis.mk.Common()
+
+    def sourceText = ""
+    def defaultSourceText = "- _FOO: _BAR"
+    if (step['repeat_with_parameters_from_yaml']) {
+        def sourceParameter = ["repeat_with_parameters_from_yaml": step['repeat_with_parameters_from_yaml']]
+        for (parameter in generateParameters(sourceParameter, global_variables)) {
+            if (parameter.name == "repeat_with_parameters_from_yaml") {
+                sourceText = parameter.value
+                common.infoMsg("'repeat_with_parameters_from_yaml' is defined, using it as a yaml text:\n${sourceText}")
+            }
+        }
+    }
+    if (!sourceText) {
+        sourceText = defaultSourceText
+        common.warningMsg("'repeat_with_parameters_from_yaml' is not defined. To get one iteration, use default single entry:\n${sourceText}")
+    }
+    def iterateParametersList = readYaml text: sourceText
+    if (!(iterateParametersList instanceof List)) {
+        // Stop the pipeline if there is wrong parameters data type, to not generate parallel jobs for wrong data
+        error "Expected a List in 'repeat_with_parameters_from_yaml' for 'parallel' step, but got:\n${sourceText}"
+    }
+
+    // Limit the maximum steps in parallel at the same time
+    def max_concurrent = (step['max_concurrent'] ?: 100).toInteger()
+    // Sleep for the specified amount of time until a free thread will be available
+    def max_concurrent_interval = (step['max_concurrent_interval'] ?: 600).toInteger()
+    // Check that failed jobs is not >= free executors. if 'true', then don't wait for free executors, fail the parallel step
+    def check_failed_concurrent = (step['check_failed_concurrent'] ?: false).toBoolean()
+
+    def jobs = [:]
+    def nested_step_id = 0
+    def free_concurrent = max_concurrent
+    def failed_concurrent = []
+
+    common.printMsg("${prefixMsg} Running parallel steps with the following parameters:\n${iterateParametersList}", "purple")
+
+    for (parameters in iterateParametersList) {
+        for (parallel_step in step['parallel']) {
+            def step_name = "parallel#${nested_step_id}"
+            def nested_step = parallel_step
+            def nested_step_name = step_name
+            def nested_prefix_name = "${prefixMsg}${nested_step_name} | "
+
+            nested_steps_data[step_name] = []
+            prepareJobsData([nested_step,], 'parallel', nested_steps_data[step_name])
+
+            //Copy global variables and merge "parameters" dict into it for the current particular step
+            def nested_global_variables = global_variables.clone()
+            nested_global_variables << parameters
+
+            jobs[step_name] = {
+                // initialRecurrencePeriod in milliseconds
+                waitUntil(initialRecurrencePeriod: 1500, quiet: true) {
+                    if (check_failed_concurrent) {
+                        if (failed_concurrent.size() >= max_concurrent){
+                            common.errorMsg("Failed jobs count is equal max_concurrent value ${max_concurrent}. Will not continue because resources are consumed")
+                            error("max_concurrent == failed_concurrent")
+                        }
+                    }
+                    if (free_concurrent > 0) {
+                        free_concurrent--
+                        true
+                    } else {
+                        sleep(max_concurrent_interval)
+                        false
+                    }
+                }
+
+                try {
+                    runWorkflowStep(nested_global_variables, nested_step, 0, nested_steps_data[nested_step_name], global_jobs_data, failed_jobs, false, artifactoryBaseUrl, artifactoryServer, scriptsLibrary, nested_prefix_name)
+                }
+                catch (e) {
+                    failed_concurrent.add(step_name)
+                    throw(e)
+                }
+
+                free_concurrent++
+            } // 'jobs' closure
+
+            nested_step_id++
+        }
+    }
+
+    def parallelSummary = [
+      nested_result       : '',
+      desc                : step['description'] ?: '',
+      nested_steps_data   : [:],
+    ]
+
+    if (iterateParametersList) {
+        // Run parallel iterations
+        try {
+            common.infoMsg("${prefixMsg} Run steps in parallel")
+
+            parallel jobs
+
+            parallelSummary['nested_result'] = 'SUCCESS'
+        } catch (InterruptedException e) {
+            parallelSummary['nested_result'] = 'ABORTED'
+            printStackTrace(e)
+        } catch (e) {
+            parallelSummary['nested_result'] = 'FAILURE'
+            printStackTrace(e)
+        }
+        parallelSummary['nested_steps_data'] = nested_steps_data
+    }
+    else
+    {
+        // No parameters were provided to iterate
+        common.errorMsg("${prefixMsg} No parameters were provided to iterate, skipping 'parallel' step")
+        parallelSummary['nested_result'] = 'SUCCESS'
+    }
+    return parallelSummary
+}
+
+
+def runSequence(global_variables, step, failed_jobs, global_jobs_data, nested_steps_data, artifactoryBaseUrl = '', artifactoryServer = '', scriptsLibrary = null, prefixMsg = '') {
+    // Run the steps in the specified order, like in main workflow, but repeat the sequence for each parameters set from 'repeat_with_parameters_from_yaml'
+    // If 'repeat_with_parameters_from_yaml' is not provided, then 'sequence' step will perform just one iteration for a default "- _FOO: _BAR" parameter
+    // If 'repeat_with_parameters_from_yaml' is present, but the specified artifact contains empty list '[]', then 'sequence' step will be skipped
+    // - sequence:
+    //     - job:
+    //     - job:
+    //     - script:
+    //   repeat_with_parameters_from_yaml:
+    //     type: TextParameterValue
+    //     get_variable_from_url: SI_PARALLEL_PARAMETERS
+    def common = new com.mirantis.mk.Common()
+
+    def sourceText = ""
+    def defaultSourceText = "- _FOO: _BAR"
+    if (step['repeat_with_parameters_from_yaml']) {
+        def sourceParameter = ["repeat_with_parameters_from_yaml": step['repeat_with_parameters_from_yaml']]
+        for (parameter in generateParameters(sourceParameter, global_variables)) {
+            if (parameter.name == "repeat_with_parameters_from_yaml") {
+                sourceText = parameter.value
+                common.infoMsg("'repeat_with_parameters_from_yaml' is defined, using it as a yaml text:\n${sourceText}")
+            }
+        }
+    }
+    if (!sourceText) {
+        sourceText = defaultSourceText
+        common.warningMsg("'repeat_with_parameters_from_yaml' is not defined. To get one iteration, use default single entry:\n${sourceText}")
+    }
+    def iterateParametersList = readYaml text: sourceText
+    if (!(iterateParametersList instanceof List)) {
+        // Stop the pipeline if there is wrong parameters data type, to not generate parallel jobs for wrong data
+        error "Expected a List in 'repeat_with_parameters_from_yaml' for 'sequence' step, but got:\n${sourceText}"
+    }
+
+    def jobs = [:]
+    def nested_step_id = 0
+
+    common.printMsg("${prefixMsg} Running parallel steps with the following parameters:\n${iterateParametersList}", "purple")
+
+    for (parameters in iterateParametersList) {
+        def step_name = "sequence#${nested_step_id}"
+        def nested_steps = step['sequence']
+        def nested_step_name = step_name
+        def nested_prefix_name = "${prefixMsg}${nested_step_name} | "
+
+        nested_steps_data[step_name] = []
+        prepareJobsData(nested_steps, 'sequence', nested_steps_data[step_name])
+
+        //Copy global variables and merge "parameters" dict into it for the current particular step
+        def nested_global_variables = global_variables.clone()
+        nested_global_variables << parameters
+
+        jobs[step_name] = {
+
+            runSteps(nested_steps, nested_global_variables, failed_jobs, nested_steps_data[nested_step_name], global_jobs_data, 0, false, artifactoryBaseUrl, artifactoryServer, scriptsLibrary, nested_prefix_name)
+
+        } // 'jobs' closure
+
+        nested_step_id++
+    }
+
+    def sequenceSummary = [
+      nested_result       : '',
+      desc                : step['description'] ?: '',
+      nested_steps_data   : [:],
+    ]
+
+    if (iterateParametersList) {
+        // Run sequence iterations
+        try {
+            jobs.each { stepName, job ->
+                common.infoMsg("${prefixMsg} Running sequence ${stepName}")
+                job()
+                sleep(30)
+            }
+            sequenceSummary['nested_result'] = 'SUCCESS'
+        } catch (InterruptedException e) {
+            sequenceSummary['nested_result'] = 'ABORTED'
+            printStackTrace(e)
+        } catch (e) {
+            sequenceSummary['nested_result'] = 'FAILURE'
+            printStackTrace(e)
+        }
+        sequenceSummary['nested_steps_data'] = nested_steps_data
+    }
+    else
+    {
+        // No parameters were provided to iterate
+        common.errorMsg("${prefixMsg} No parameters were provided to iterate, skipping 'sequence' step")
+        sequenceSummary['nested_result'] = 'SUCCESS'
+    }
+
+    return sequenceSummary
+}
+
+
+def checkResult(job_result, build_url, step, failed_jobs) {
+    // Check job result, in case of SUCCESS, move to next step.
+    // In case job has status NOT_BUILT, fail the build or keep going depending on 'ignore_not_built' flag
+    // In other cases check flag ignore_failed, if true ignore any statuses and keep going additionally
+    // if skip_results is not set or set to false fail entrie workflow, otherwise succed.
+    if (job_result != 'SUCCESS') {
+        def ignoreStepResult = false
+        switch (job_result) {
+        // In cases when job was waiting too long in queue or internal job logic allows to skip building,
+        // job may have NOT_BUILT status. In that case ignore_not_built flag can be used not to fail scenario.
+            case "NOT_BUILT":
+                ignoreStepResult = step['ignore_not_built'] ?: false
+                break
+            case "UNSTABLE":
+                ignoreStepResult = step['ignore_unstable'] ?: (step['ignore_failed'] ?: false)
+                if (ignoreStepResult && !step['skip_results'] ?: false) {
+                    failed_jobs[build_url] = job_result
+                }
+                break
+            default:
+                ignoreStepResult = step['ignore_failed'] ?: false
+                if (ignoreStepResult && !step['skip_results'] ?: false) {
+                    failed_jobs[build_url] = job_result
+                }
+        }
+        if (!ignoreStepResult) {
+            currentBuild.result = job_result
+            error "Job ${build_url} finished with result: ${job_result}"
+        }
+    }
+}
+
+def runWorkflowStep(global_variables, step, step_id, jobs_data, global_jobs_data, failed_jobs, propagate, artifactoryBaseUrl, artifactoryServer, scriptsLibrary = null, prefixMsg = '') {
+    def common = new com.mirantis.mk.Common()
+
+    def _sep = "\n======================\n"
+    if (step.containsKey('job')) {
+
+        common.printMsg("${_sep}${prefixMsg}Run job ${step['job']} [at ${java.time.LocalDateTime.now()}]${_sep}", "blue")
+        stage("Run job ${step['job']}") {
+
             def job_summary = runStep(global_variables, step, propagate, artifactoryBaseUrl, artifactoryServer).call()
 
             // Update jobs_data for updating description
@@ -417,46 +914,163 @@
             if (job_summary['build_description']) {
                 jobs_data[step_id]['child_desc'] = job_summary['build_description']
             }
-            updateDescription(jobs_data)
             def job_result = job_summary['job_result']
             def build_url = job_summary['build_url']
-
-            // Check job result, in case of SUCCESS, move to next step.
-            // In case job has status NOT_BUILT, fail the build or keep going depending on 'ignore_not_built' flag
-            // In other cases check flag ignore_failed, if true ignore any statuses and keep going additionally
-            // if skip_results is not set or set to false fail entrie workflow, otherwise succed.
-            if (job_result != 'SUCCESS') {
-                def ignoreStepResult = false
-                switch (job_result) {
-                // In cases when job was waiting too long in queue or internal job logic allows to skip building,
-                // job may have NOT_BUILT status. In that case ignore_not_built flag can be used not to fail scenario.
-                    case "NOT_BUILT":
-                        ignoreStepResult = step['ignore_not_built'] ?: false
-                        break;
-                    case "UNSTABLE":
-                        ignoreStepResult = step['ignore_unstable'] ?: (step['ignore_failed'] ?: false)
-                        if (ignoreStepResult && !step['skip_results'] ?: false) {
-                            failed_jobs[build_url] = job_result
-                        }
-                        break;
-                    default:
-                        ignoreStepResult = step['ignore_failed'] ?: false
-                        if (ignoreStepResult && !step['skip_results'] ?: false) {
-                            failed_jobs[build_url] = job_result
-                        }
-                }
-                if (!ignoreStepResult) {
-                    currentBuild.result = job_result
-                    error "Job ${build_url} finished with result: ${job_result}"
-                }
-            }
-            common.infoMsg("Job ${build_url} finished with result: ${job_result}")
+            common.printMsg("${_sep}${prefixMsg}Job ${build_url} finished with result: ${job_result} [at ${java.time.LocalDateTime.now()}]${_sep}", "blue")
         }
+    }
+    else if (step.containsKey('script')) {
+        common.printMsg("${_sep}${prefixMsg}Run script ${step['script']} [at ${java.time.LocalDateTime.now()}]${_sep}", "blue")
+        stage("Run script ${step['script']}") {
+
+            def scriptResult = runScript(global_variables, step, artifactoryBaseUrl, artifactoryServer, scriptsLibrary)
+
+            // Use build_url just as an unique key for failed_jobs.
+            // All characters after '#' are 'comment'
+            def build_url = "${env.BUILD_URL}#${step_id}:${step['script']}"
+            def job_result = scriptResult['script_result']
+            common.printMsg("${_sep}${prefixMsg}Script ${build_url} finished with result: ${job_result} [at ${java.time.LocalDateTime.now()}]${_sep}", "blue")
+
+            jobs_data[step_id]['build_url'] = build_url
+            jobs_data[step_id]['status'] = scriptResult['script_result']
+            jobs_data[step_id]['desc'] = scriptResult['desc']
+            if (scriptResult['build_description']) {
+                jobs_data[step_id]['child_desc'] = scriptResult['build_description']
+            }
+        }
+    }
+    else if (step.containsKey('parallel')) {
+        common.printMsg("${_sep}${prefixMsg}Run steps in parallel [at ${java.time.LocalDateTime.now()}]:${_sep}", "blue")
+        stage("Run steps in parallel:") {
+
+            // Allocate a map to collect nested steps data for updateDescription()
+            def nested_steps_data = [:]
+            jobs_data[step_id]['nested_steps_data'] = nested_steps_data
+
+            def parallelResult = runParallel(global_variables, step, failed_jobs, global_jobs_data, nested_steps_data, artifactoryBaseUrl, artifactoryServer, scriptsLibrary, prefixMsg)
+
+            // Use build_url just as an unique key for failed_jobs.
+            // All characters after '#' are 'comment'
+            def build_url = "${env.BUILD_URL}#${step_id}"
+            def job_result = parallelResult['nested_result']
+            common.printMsg("${_sep}${prefixMsg}Parallel steps ${build_url} finished with result: ${job_result} [at ${java.time.LocalDateTime.now()}]${_sep}", "blue")
+
+            jobs_data[step_id]['build_url'] = build_url
+            jobs_data[step_id]['status'] = parallelResult['nested_result']
+            jobs_data[step_id]['desc'] = parallelResult['desc']
+            if (parallelResult['build_description']) {
+                jobs_data[step_id]['child_desc'] = parallelResult['build_description']
+            }
+        }
+    }
+    else if (step.containsKey('sequence')) {
+        common.printMsg("${_sep}${prefixMsg}Run steps in sequence [at ${java.time.LocalDateTime.now()}]:${_sep}", "blue")
+        stage("Run steps in sequence:") {
+
+            // Allocate a map to collect nested steps data for updateDescription()
+            def nested_steps_data = [:]
+            jobs_data[step_id]['nested_steps_data'] = nested_steps_data
+
+            def sequenceResult = runSequence(global_variables, step, failed_jobs, global_jobs_data, nested_steps_data, artifactoryBaseUrl, artifactoryServer, scriptsLibrary, prefixMsg)
+
+            // Use build_url just as an unique key for failed_jobs.
+            // All characters after '#' are 'comment'
+            def build_url = "${env.BUILD_URL}#${step_id}"
+            def job_result = sequenceResult['nested_result']
+            common.printMsg("${_sep}${prefixMsg}Sequence steps ${build_url} finished with result: ${job_result} [at ${java.time.LocalDateTime.now()}]${_sep}", "blue")
+
+            jobs_data[step_id]['build_url'] = build_url
+            jobs_data[step_id]['status'] = sequenceResult['nested_result']
+            jobs_data[step_id]['desc'] = sequenceResult['desc']
+            if (sequenceResult['build_description']) {
+                jobs_data[step_id]['child_desc'] = sequenceResult['build_description']
+            }
+        }
+    }
+
+    updateDescription(global_jobs_data)
+
+    job_result = jobs_data[step_id]['status']
+    checkResult(job_result, build_url, step, failed_jobs)
+
+//    return build_url
+
+}
+
+/**
+ * Run the workflow or final steps one by one
+ *
+ * @param steps                   List of steps (Jenkins jobs) to execute
+ * @param global_variables        Map where the collected artifact URLs and 'env' objects are stored
+ * @param failed_jobs             Map with failed job names and result statuses, to report it later
+ * @param jobs_data               Map with all job names and result statuses, to showing it in description
+ * @param step_id                 Counter for matching step ID with cell ID in description table
+ * @param propagate               Boolean. If false: allows to collect artifacts after job is finished, even with FAILURE status
+ *                                If true: immediatelly fails the pipeline. DO NOT USE 'true' with runScenario().
+ */
+def runSteps(steps, global_variables, failed_jobs, jobs_data, global_jobs_data, step_id, Boolean propagate = false, artifactoryBaseUrl = '', artifactoryServer = '', scriptsLibrary = null, prefixMsg = '') {
+    // Show expected jobs list in description
+    updateDescription(global_jobs_data)
+
+    for (step in steps) {
+
+        runWorkflowStep(global_variables, step, step_id, jobs_data, global_jobs_data, failed_jobs, propagate, artifactoryBaseUrl, artifactoryServer, scriptsLibrary, prefixMsg)
+
         // Jump to next ID for updating next job data in description table
         step_id++
     }
 }
 
+
+/**
+ * Prepare jobs_data for generating the scenario description
+ */
+def prepareJobsData(scenario_steps, step_type, jobs_data) {
+    def list_id = jobs_data.size()
+
+    for (step in scenario_steps) {
+        def display_name = ''
+        def step_key = ''
+        def desc = ''
+
+        if (step.containsKey('job')) {
+            display_name = step['job']
+            step_key = 'job'
+        }
+        else if (step.containsKey('script')) {
+            display_name = step['script']
+            step_key = 'script'
+        }
+        else if (step.containsKey('parallel')) {
+            display_name = 'Parallel steps'
+            step_key = 'parallel'
+        }
+        else if (step.containsKey('sequence')) {
+            display_name = 'Sequence steps'
+            step_key = 'sequence'
+        }
+
+        if (step['description'] != null && step['description'] != 'null' && step['description'].toString() != '') {
+            desc = (step['description'] ?: '').toString()
+        }
+
+        jobs_data.add([list_id      : "$list_id",
+                       type         : step_type,
+                       name         : "$display_name",
+                       build_url    : "0",
+                       build_id     : "-",
+                       status       : "-",
+                       desc         : desc,
+                       child_desc   : "",
+                       duration     : '-',
+                       step_key     : step_key,
+                       together_steps: [],
+                      ])
+        list_id += 1
+    }
+}
+
+
 /**
  * Run the workflow scenario
  *
@@ -536,97 +1150,50 @@
  *   wf_pause_step_slack_report_channel: If step paused, send message about it in slack.
  *   wf_pause_step_timeout: timeout im minutes to wait for manual unpause.
  */
+def runScenario(scenario, slackReportChannel = '', artifactoryBaseUrl = '', Boolean logGlobalVariables = false, artifactoryServer = '', scriptsLibrary = null,
+                global_variables = null, failed_jobs = null, jobs_data = null) {
+    def common = new com.mirantis.mk.Common()
 
-
-def runScenario(scenario, slackReportChannel = '', artifactoryBaseUrl = '', Boolean logGlobalVariables = false, artifactoryServer = '') {
-    runScenario(['scenario'          : scenario,
-                 'slackReportChannel': slackReportChannel,
-                 'artifactoryBaseUrl': artifactoryBaseUrl,
-                 'logGlobalVariables': logGlobalVariables,
-                 'artifactoryServer' : artifactoryServer,
-    ])
-}
-
-def runScenario(Map opts) {
-    Map scenario = opts['scenario']
-    String slackReportChannel = opts.getOrDefault('slackReportChannel', '')
-    String artifactoryBaseUrl = opts.getOrDefault('artifactoryBaseUrl', '')
-    Boolean logGlobalVariables = opts.getOrDefault('logGlobalVariables', false)
-    String artifactoryServer = opts.getOrDefault('artifactoryServer', '')
     // Clear description before adding new messages
     currentBuild.description = ''
     // Collect the parameters for the jobs here
-    def global_variables = [:]
+    if (global_variables == null) {
+        global_variables = [:]
+    }
     // List of failed jobs to show at the end
-    def failed_jobs = [:]
+    if (failed_jobs == null) {
+        failed_jobs = [:]
+    }
     // Jobs data to use for wf job build description
-    def jobs_data = []
+    if (jobs_data == null) {
+        jobs_data = []
+    }
+    def global_jobs_data = jobs_data
+
     // Counter for matching step ID with cell ID in description table
-    def step_id = 0
-
+    def step_id = jobs_data.size()
     // Generate expected list jobs for description
-    def list_id = 0
-    for (step in scenario['workflow']) {
-        def display_name = step['job']
-        if (step['description'] != null && step['description'] != 'null' && step['description'].toString() != '') {
-            display_name = step['description']
-        }
-        jobs_data.add([list_id   : "$list_id",
-                       type      : "workflow",
-                       name      : "$display_name",
-                       build_url : "0",
-                       build_id  : "-",
-                       status    : "-",
-                       desc      : "",
-                       child_desc: "",
-                       duration  : '-'])
-        list_id += 1
-    }
+    prepareJobsData(scenario['workflow'], 'workflow', jobs_data)
 
-    def pause_step_id = list_id
-    for (step in scenario['pause']) {
-        def display_name = step['job']
-        if (step['description'] != null && step['description'].toString() != "") {
-            display_name = step['description']
-        }
-        jobs_data.add([list_id   : "$list_id",
-                       type      : "pause",
-                       name      : "$display_name",
-                       build_url : "0",
-                       build_id  : "-",
-                       status    : "-",
-                       desc      : "",
-                       child_desc: "",
-                       duration  : '-'])
-        list_id += 1
-    }
+    def pause_step_id = jobs_data.size()
+    // Generate expected list jobs for description
+    prepareJobsData(scenario['pause'], 'pause', jobs_data)
 
-    def finally_step_id = list_id
-    for (step in scenario['finally']) {
-        def display_name = step['job']
-        if (step['description'] != null && step['description'].toString() != "") {
-            display_name = step['description']
-        }
-        jobs_data.add([list_id   : "$list_id",
-                       type      : "finally",
-                       name      : "$display_name",
-                       build_url : "0",
-                       build_id  : "-",
-                       status    : "-",
-                       desc      : "",
-                       child_desc: "",
-                       duration  : '-'])
-        list_id += 1
-    }
+    def finally_step_id = jobs_data.size()
+    // Generate expected list jobs for description
+    prepareJobsData(scenario['finally'], 'finally', jobs_data)
+
+
     def job_failed_flag = false
     try {
         // Run the 'workflow' jobs
-        runSteps(scenario['workflow'], global_variables, failed_jobs, jobs_data, step_id, false, artifactoryBaseUrl, artifactoryServer)
-    } catch (InterruptedException x) {
+        runSteps(scenario['workflow'], global_variables, failed_jobs, jobs_data, global_jobs_data, step_id, false, artifactoryBaseUrl, artifactoryServer, scriptsLibrary, '')
+    } catch (InterruptedException e) {
         job_failed_flag = true
         error "The job was aborted"
     } catch (e) {
         job_failed_flag = true
+        printStackTrace(e)
         error("Build failed: " + e.toString())
 
     } finally {
@@ -635,7 +1202,7 @@
             printVariables(global_variables)
         }
 
-        flag_pause_variable = (env.PAUSE_FOR_DEBUG) != null
+        def flag_pause_variable = (env.PAUSE_FOR_DEBUG) != null
         // Run the 'finally' or 'pause' jobs
         common.infoMsg(failed_jobs)
         // Run only if there are failed jobs in the scenario
@@ -643,13 +1210,13 @@
             // Switching to 'pause' step index
             common.infoMsg("FINALLY BLOCK - PAUSE")
             step_id = pause_step_id
-            runSteps(scenario['pause'], global_variables, failed_jobs, jobs_data, step_id, false, artifactoryBaseUrl, artifactoryServer)
+            runSteps(scenario['pause'], global_variables, failed_jobs, jobs_data, global_jobs_data, step_id, false, artifactoryBaseUrl, artifactoryServer, scriptsLibrary, '')
 
         }
          // Switching to 'finally' step index
         common.infoMsg("FINALLY BLOCK - CLEAR")
         step_id = finally_step_id
-        runSteps(scenario['finally'], global_variables, failed_jobs, jobs_data, step_id, false, artifactoryBaseUrl, artifactoryServer)
+        runSteps(scenario['finally'], global_variables, failed_jobs, jobs_data, global_jobs_data, step_id, false, artifactoryBaseUrl, artifactoryServer, scriptsLibrary, '')
 
         if (failed_jobs) {
             def statuses = []
@@ -660,8 +1227,7 @@
                 currentBuild.result = 'FAILURE'
             } else if (statuses.contains('ABORTED')) {
                 currentBuild.result = 'ABORTED'
-            }
-            else if (statuses.contains('UNSTABLE')) {
+            } else if (statuses.contains('UNSTABLE')) {
                 currentBuild.result = 'UNSTABLE'
             } else {
                 currentBuild.result = 'FAILURE'
@@ -679,3 +1245,47 @@
         }
     } // finally
 }
+
+
+def manageArtifacts(entrypointDirectory, storeArtsInJenkins = false, artifactoryServerName = 'mcp-ci') {
+    def mcpArtifactory = new com.mirantis.mcp.MCPArtifactory()
+    def artifactoryRepoPath = "si-local/jenkins-job-artifacts/${JOB_NAME}/${BUILD_NUMBER}"
+    def tests_log = "${entrypointDirectory}/tests.log"
+
+    if (fileExists(tests_log)) {
+        try {
+            def size = sh([returnStdout: true, script: "stat --printf='%s' ${tests_log}"]).trim().toInteger()
+            // do not archive unless it is more than 50 MB
+            def allowed_size = 1048576 * 50
+            if (size >= allowed_size) {
+                sh("gzip ${tests_log} || true")
+            }
+        } catch (e) {
+            print("Cannot determine tests.log filesize: ${e}")
+        }
+    }
+
+    if (storeArtsInJenkins) {
+        archiveArtifacts(
+            artifacts: "${entrypointDirectory}/**",
+            allowEmptyArchive: true
+        )
+    }
+    artConfig = [
+        deleteArtifacts: false,
+        artifactory    : artifactoryServerName,
+        artifactPattern: "${entrypointDirectory}/**",
+        artifactoryRepo: "artifactory/${artifactoryRepoPath}",
+    ]
+    def artDescription = mcpArtifactory.uploadArtifactsToArtifactory(artConfig)
+    currentBuild.description += "${artDescription}<br>"
+
+    junit(testResults: "${entrypointDirectory}/**/*.xml", allowEmptyResults: true)
+
+    def artifactoryServer = Artifactory.server(artifactoryServerName)
+    def artifactsUrl = "${artifactoryServer.getUrl()}/artifactory/${artifactoryRepoPath}"
+    return artifactsUrl
+}
+
+
+return this
