add update salt environment pipeline

Change-Id: I1b6fd693981079d9c6ebaff2208d074801a7f5e7
diff --git a/update-salt-environment.groovy b/update-salt-environment.groovy
new file mode 100644
index 0000000..0b570fc
--- /dev/null
+++ b/update-salt-environment.groovy
@@ -0,0 +1,54 @@
+/**
+ *
+ * Update Salt environment pipeline
+ *
+ * Expected parameters:
+ *   SALT_MASTER_URL            Salt API server location
+ *   SALT_MASTER_CREDENTIALS    Credentials to the Salt API
+ *   UPDATE_FORMULAS            Boolean switch for enforcing updating formulas
+ */
+
+// Load shared libs
+def salt = new com.mirantis.mk.Salt()
+def common = new com.mirantis.mk.Common()
+def python = new com.mirantis.mk.Python()
+def venvPepper = "venvPepper"
+
+node() {
+    try {
+        python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
+
+        stage("Update formulas"){
+            if(UPDATE_FORMULAS.toBoolean()){
+                common.infoMsg("Updating salt formulas")
+                salt.cmdRun(
+                    venvPepper,
+                    "I@salt:master",
+                    'apt-get update && apt-get install -y salt-formula-*'
+                )
+                common.infoMsg("Running salt sync-all")
+                salt.runSaltProcessStep(venvPepper, 'jma*', 'saltutil.sync_all', [], null, true)
+            }
+        }
+        stage("Update Reclass") {
+            common.infoMsg("Updating reclass model")
+            salt.cmdRun(
+                venvPepper,
+                "I@salt:master",
+                'cd /srv/salt/reclass && git pull -r && git submodule update',
+                false
+            )
+
+            salt.enforceState(
+                venvPepper,
+                "I@salt:master",
+                'reclass',
+                true
+            )
+        }
+    } catch (Throwable e) {
+        // If there was an error or exception thrown, the build failed
+        currentBuild.result = "FAILURE"
+        throw e
+    }
+}
\ No newline at end of file