blob: 677228898d20c486d5dd1c177d3fe423239e8976 [file] [log] [blame]
Sergey Kulanov1bbd3612016-09-30 11:40:11 +03001package ci.mcp
2
3/**
4 * https://issues.jenkins-ci.org/browse/JENKINS-26481
5 * fix groovy List.collect()
Sergey Kulanov56d0d052016-10-13 15:48:56 +03006**/
7@NonCPS
8def constructString(ArrayList options, String keyOption, String separator = " ") {
9 return options.collect{ keyOption + it }.join(separator).replaceAll("\n", "")
10}
11
12/**
Sergey Kulanov1bbd3612016-09-30 11:40:11 +030013 * 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 Kulanov1bbd3612016-09-30 11:40:11 +030025def getCommandBuilder(ArrayList options, String keyOption, String separator = " ") {
Sergey Kulanov56d0d052016-10-13 15:48:56 +030026 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**/
36def 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 Kulanov1bbd3612016-09-30 11:40:11 +030052}