Sergey Kulanov | 1bbd361 | 2016-09-30 11:40:11 +0300 | [diff] [blame] | 1 | package ci.mcp |
| 2 | |
| 3 | /** |
| 4 | * https://issues.jenkins-ci.org/browse/JENKINS-26481 |
| 5 | * fix groovy List.collect() |
Sergey Kulanov | 56d0d05 | 2016-10-13 15:48:56 +0300 | [diff] [blame^] | 6 | **/ |
| 7 | @NonCPS |
| 8 | def constructString(ArrayList options, String keyOption, String separator = " ") { |
| 9 | return options.collect{ keyOption + it }.join(separator).replaceAll("\n", "") |
| 10 | } |
| 11 | |
| 12 | /** |
Sergey Kulanov | 1bbd361 | 2016-09-30 11:40:11 +0300 | [diff] [blame] | 13 | * Build command line options, e.g: |
| 14 | * cmd_opts=["a=b", "c=d", "e=f"] |
| 15 | * key = "--build-arg " |
| 16 | * separator = " " |
| 17 | * def options = getCommandBuilder(cmd_opts, key, separator) |
| 18 | * println options |
| 19 | * > --build-arg a=b --build-arg c=d --build-arg e=f |
| 20 | * |
| 21 | * @param options List of Strings (options that should be populated) |
| 22 | * @param keyOption key that should be added before each option |
| 23 | * @param separator Separator between key+Option pairs |
| 24 | */ |
Sergey Kulanov | 1bbd361 | 2016-09-30 11:40:11 +0300 | [diff] [blame] | 25 | def getCommandBuilder(ArrayList options, String keyOption, String separator = " ") { |
Sergey Kulanov | 56d0d05 | 2016-10-13 15:48:56 +0300 | [diff] [blame^] | 26 | return constructString(options, keyOption) |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Return string of mandatory build properties for binaries |
| 31 | * User can also add some custom properties |
| 32 | * |
| 33 | * @param customProperties a Array of Strings that should be added to mandatory props |
| 34 | * in format ["prop1=value1", "prop2=value2"] |
| 35 | **/ |
| 36 | def getBinaryBuildProperties(ArrayList customProperties) { |
| 37 | |
| 38 | def namespace = "com.mirantis." |
| 39 | def properties = [ |
| 40 | "gerritProject=${env.GERRIT_PROJECT}", |
| 41 | "gerritChangeNumber=${env.GERRIT_CHANGE_NUMBER}", |
| 42 | "gerritPatchsetNumber=${env.GERRIT_PATCHSET_NUMBER}", |
| 43 | "gerritChangeId=${env.GERRIT_CHANGE_ID}", |
| 44 | "gitSha=${env.GERRIT_PATCHSET_REVISION}" |
| 45 | ] |
| 46 | |
| 47 | if (customProperties){ |
| 48 | properties.addAll(customProperties) |
| 49 | } |
| 50 | |
| 51 | return constructString(properties, namespace, ";") |
Sergey Kulanov | 1bbd361 | 2016-09-30 11:40:11 +0300 | [diff] [blame] | 52 | } |