Add getCommandBuilder command
We need to have an ability to build command line options for
docker command, e.g:
docker build --build-arg CALICO_REPO=repo \
--build-arg CALICO_VER=mcp-0.1 \
--build-arg LIBCALICO_REPO=repo \
--build-arg LIBCALICO_VER=mcp-0.1
...
This can be easily done by groovy and works in jenkins
["opt1", "opt2", "opt3"].collect{ "--build-arg " + it }.join(" ")
but doesn't for pipelines because of [1], so we need to
have our own bicycle - the first one, but not the last
[1]. https://issues.jenkins-ci.org/browse/JENKINS-26481
Change-Id: I5e06b305fc7e3d0c26c847779ec8a1ad81850e51
diff --git a/src/ci/mcp/Tools.groovy b/src/ci/mcp/Tools.groovy
new file mode 100644
index 0000000..2c1986f
--- /dev/null
+++ b/src/ci/mcp/Tools.groovy
@@ -0,0 +1,22 @@
+package ci.mcp
+
+/**
+ * https://issues.jenkins-ci.org/browse/JENKINS-26481
+ * fix groovy List.collect()
+ * Build command line options, e.g:
+ * cmd_opts=["a=b", "c=d", "e=f"]
+ * key = "--build-arg "
+ * separator = " "
+ * def options = getCommandBuilder(cmd_opts, key, separator)
+ * println options
+ * > --build-arg a=b --build-arg c=d --build-arg e=f
+ *
+ * @param options List of Strings (options that should be populated)
+ * @param keyOption key that should be added before each option
+ * @param separator Separator between key+Option pairs
+ */
+
+@NonCPS
+def getCommandBuilder(ArrayList options, String keyOption, String separator = " ") {
+ return options.collect{ keyOption + it }.join(separator).replaceAll("\n", "")
+}