Ruslan Kamaldinov | 90d4e67 | 2016-11-11 18:31:00 +0300 | [diff] [blame] | 1 | package com.mirantis.mcp |
| 2 | |
| 3 | /** |
| 4 | * Add LABEL to the end of the Dockerfile |
| 5 | * User can also add some custom properties |
| 6 | * |
| 7 | * @param dockerfilePath is the path to Dockerfile, the default is ./Dockerfile |
| 8 | * @param customProperties a Array of Strings that should be added to mandatory props |
| 9 | * in format ["prop1=value1", "prop2=value2"] |
| 10 | * */ |
| 11 | def setDockerfileLabels(String dockerfilePath = "./Dockerfile", ArrayList customProperties = null) { |
| 12 | |
| 13 | if (!fileExists(dockerfilePath)) { |
| 14 | throw new RuntimeException("Unable to add LABEL to Dockerfile, ${dockerfilePath} doesn't exists") |
| 15 | } |
| 16 | echo "Updating ${dockerfilePath}" |
| 17 | |
| 18 | def namespace = "com.mirantis.image-specs." |
| 19 | def properties = [ |
| 20 | "gerritProject=${env.GERRIT_PROJECT}", |
| 21 | "gerritChangeNumber=${env.GERRIT_CHANGE_NUMBER}", |
| 22 | "gerritPatchsetNumber=${env.GERRIT_PATCHSET_NUMBER}", |
| 23 | "gerritChangeId=${env.GERRIT_CHANGE_ID}", |
| 24 | "gerritPatchsetRevision=${env.GERRIT_PATCHSET_REVISION}" |
| 25 | ] |
| 26 | |
| 27 | if (customProperties != null) { |
| 28 | properties.addAll(customProperties) |
| 29 | } |
| 30 | def common = new com.mirantis.mcp.Common() |
| 31 | def metadata = common.constructString(properties, namespace, " ") |
| 32 | sh """ |
| 33 | cat <<EOF>> ${dockerfilePath} |
| 34 | # Apply additional build metadata |
| 35 | LABEL ${metadata} |
| 36 | """ |
| 37 | return metadata |
| 38 | } |