Ales Komarek | 1fe5b8f | 2017-03-06 11:07:54 +0100 | [diff] [blame^] | 1 | /** |
| 2 | * Update packages pipeline script |
| 3 | * |
| 4 | * Expected parameters: |
| 5 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API (str) |
| 6 | * SALT_MASTER_URL URL of Salt-API (str) |
| 7 | * |
| 8 | * UPDATE_SERVERS Salt target for updated servers (str) |
| 9 | * UPDATE_COMMIT Confirm update should be performed (boot) |
| 10 | * UPDATE_PACKAGES List of packages to update |
| 11 | * |
| 12 | **/ |
| 13 | |
| 14 | |
| 15 | |
| 16 | def common = new com.mirantis.mk.Common() |
| 17 | def salt = new com.mirantis.mk.Salt() |
| 18 | timestamps { |
| 19 | node() { |
| 20 | try { |
| 21 | |
| 22 | stage("Connect to Salt master") { |
| 23 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 24 | } |
| 25 | |
| 26 | stage("Get package versions") { |
| 27 | salt.runSaltProcessStep(saltMaster, UPDATE_SERVERS, 'pkg.list_upgrades', [], null, true) |
| 28 | } |
| 29 | |
| 30 | if (UPDATE_COMMIT == true) { |
| 31 | stage("Update packages") { |
| 32 | if (UPDATE_PACKAGES == "") { |
| 33 | salt.runSaltProcessStep(saltMaster, UPDATE_SERVERS, 'pkg.install', [], null, true) |
| 34 | } |
| 35 | else { |
| 36 | salt.runSaltProcessStep(saltMaster, UPDATE_SERVERS, 'pkg.install', UPDATE_PACKAGES.split(' '), null, true) |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | } catch (Throwable e) { |
| 42 | // If there was an error or exception thrown, the build failed |
| 43 | currentBuild.result = "FAILURE" |
| 44 | throw e |
| 45 | } finally { |
| 46 | // common.sendNotification(currentBuild.result,"",["slack"]) |
| 47 | } |
| 48 | } |
| 49 | } |