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 | |
Tomáš Kukrál | 1ece6c8 | 2017-03-06 15:16:47 +0100 | [diff] [blame] | 30 | if (UPDATE_COMMIT.toBoolean() == true) { |
Ales Komarek | 1fe5b8f | 2017-03-06 11:07:54 +0100 | [diff] [blame] | 31 | stage("Update packages") { |
| 32 | if (UPDATE_PACKAGES == "") { |
| 33 | salt.runSaltProcessStep(saltMaster, UPDATE_SERVERS, 'pkg.install', [], null, true) |
Tomáš Kukrál | 1ece6c8 | 2017-03-06 15:16:47 +0100 | [diff] [blame] | 34 | } else { |
Ales Komarek | 1fe5b8f | 2017-03-06 11:07:54 +0100 | [diff] [blame] | 35 | salt.runSaltProcessStep(saltMaster, UPDATE_SERVERS, 'pkg.install', UPDATE_PACKAGES.split(' '), null, true) |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | } catch (Throwable e) { |
| 41 | // If there was an error or exception thrown, the build failed |
| 42 | currentBuild.result = "FAILURE" |
| 43 | throw e |
| 44 | } finally { |
| 45 | // common.sendNotification(currentBuild.result,"",["slack"]) |
| 46 | } |
| 47 | } |
| 48 | } |