Sergey Kulanov | 56d0d05 | 2016-10-13 15:48:56 +0300 | [diff] [blame] | 1 | getBinaryBuildProperties |
| 2 | ------------------------ |
| 3 | |
| 4 | 1. getBinaryBuildProperties() should be used to define mandatory |
| 5 | properties for binary artifact, which are: |
| 6 | |
| 7 | "gerritProject=${env.GERRIT_PROJECT}", |
| 8 | "gerritChangeNumber=${env.GERRIT_CHANGE_NUMBER}", |
| 9 | "gerritPatchsetNumber=${env.GERRIT_PATCHSET_NUMBER}", |
| 10 | "gerritChangeId=${env.GERRIT_CHANGE_ID}", |
| 11 | "gitSha=${env.GERRIT_PATCHSET_REVISION}" |
| 12 | |
| 13 | 2. User can add some custom properties, e.g: |
| 14 | |
| 15 | def properties = tools.getBinaryBuildProperties( |
| 16 | ["test=123", |
| 17 | "prop1=val1", |
| 18 | prop2=val2" |
| 19 | ]) |
| 20 | |
| 21 | 3. The resulting values will be the string in props format with |
| 22 | namespace com.mirantis, e.g: |
| 23 | |
| 24 | com.mirantis.gerritProject=asd;com.mirantis.gerritChangeNumber=123;com.mirantis.gerritChangeId=ddd |
| 25 | |
| 26 | 4. How to use: |
| 27 | |
| 28 | def tools = new ci.mcp.Tools() |
| 29 | ... |
| 30 | def buildInfo = Artifactory.newBuildInfo() |
| 31 | ... |
| 32 | def properties = tools.getBinaryBuildProperties() |
| 33 | ... |
| 34 | // Create the upload spec. |
| 35 | def uploadSpec = """{ |
| 36 | "files": [ |
| 37 | { |
| 38 | "pattern": "**", |
| 39 | "target": "some/target", |
| 40 | "props": "${properties}" |
| 41 | } |
| 42 | ] |
| 43 | }""" |
| 44 | server.upload(uploadSpec, buildInfo) |
| 45 | server.publishBuildInfo buildInfo |
Denis Egorenko | e355268 | 2016-10-18 13:29:29 +0300 | [diff] [blame] | 46 | |
| 47 | |
Sergey Kulanov | 20c8b13 | 2016-11-02 13:24:32 +0200 | [diff] [blame] | 48 | setDockerfileLabels |
| 49 | ------------------- |
| 50 | // simple usage, which adds mandatory properties to Dockerfile which is |
| 51 | // located in current directory |
| 52 | tools.setDockerfileLabels() |
| 53 | |
| 54 | // extended usage |
| 55 | // add Labels to calico ctl and node images |
| 56 | def properties = [ |
| 57 | "CALICO_NODE_IMAGE_REPO=${calicoNodeImageRepo}", |
| 58 | "CALICOCTL_IMAGE_REPO=${calicoCtlImageRepo}", |
| 59 | "CALICO_VERSION=${calicoVersion}" |
| 60 | ] |
| 61 | tools.setDockerfileLabels("./calicoctl/Dockerfile", properties) |
| 62 | tools.setDockerfileLabels("./calico_node/Dockerfile", properties) |
| 63 | |
| 64 | |
| 65 | |
Denis Egorenko | e355268 | 2016-10-18 13:29:29 +0300 | [diff] [blame] | 66 | uriByProperties |
| 67 | --------------- |
| 68 | |
| 69 | 1. uriByProperties() should be used to get URL for some artifact |
| 70 | with specified properties, like: |
| 71 | |
| 72 | "gerritChangeId=${env.GERRIT_CHANGE_ID}", |
| 73 | "gerritPatchsetNumber=${env.GERRIT_PATCHSET_NUMBER}" |
| 74 | |
| 75 | 2. Also can be used custom user' properties. |
| 76 | |
| 77 | 3. The resulting value will be the string in URL format, e.g: |
| 78 | |
| 79 | "https://ci.mcp-ci.local/artifactory/mcp-k8s-ci/images-info/conformance_image_v1.4.1-5_1476965708283.yaml" |
| 80 | |
| 81 | 4. How to use: |
| 82 | |
| 83 | def tools = new ci.mcp.Tools() |
| 84 | ... |
| 85 | def properties = ['com.mirantis.changeid': "${env.GERRIT_CHANGE_ID}", |
| 86 | 'com.mirantis.patchset_number': "${env.GERRIT_PATCHSET_NUMBER}" ] |
| 87 | def artifact_uri = tools.uriByProperties(properties) |
| 88 | |
| 89 | 5. Important notes: |
| 90 | |
| 91 | - if specified properties are set for few artifacts will be taken last. |
| 92 | |
| 93 | |
| 94 | setProperties |
| 95 | ------------- |
| 96 | |
| 97 | 1. setProperties() should be used to set some properties to specified artifact in repo, like: |
| 98 | |
| 99 | "gerritChangeId=${env.GERRIT_CHANGE_ID}", |
| 100 | "gerritPatchsetNumber=${env.GERRIT_PATCHSET_NUMBER}" |
| 101 | |
| 102 | 2. How to use: |
| 103 | |
| 104 | def tools = new ci.mcp.Tools() |
| 105 | ... |
| 106 | def artifact_url = "${env.ARTIFACTORY_URL}/api/storage/${repository}/${tag}/${version}" |
| 107 | // for example: https://ci.mcp-ci.local/artifactory/api/storage/mcp-k8s-local/hyperkube-amd64/v1.4.1-5 |
| 108 | def properties = ['com.mirantis.build_name':"${env.JOB_NAME}", |
| 109 | 'com.mirantis.build_id': "${env.BUILD_NUMBER}", |
| 110 | 'com.mirantis.changeid': "${env.GERRIT_CHANGE_ID}", |
| 111 | 'com.mirantis.patchset_number': "${env.GERRIT_PATCHSET_NUMBER}"] |
| 112 | |
| 113 | tools.setProperties(artifact_url, properties) |
| 114 | |
| 115 | 3. As result provided artifact in repo will be tagged by specified properties. |
| 116 | |
| 117 | |
| 118 | getPropertiesForArtifact |
| 119 | ------------------------ |
| 120 | |
| 121 | 1. getPropertiesForArtifact() should be used to get properties for specified artifact in repo, like: |
| 122 | |
| 123 | "https://ci.mcp-ci.local:443/artifactory/api/storage/mcp-k8s-ci/hyperkube-amd64/v1.4.1-5" |
| 124 | |
| 125 | 2. As a result will be returned LinkedHashMap of properties for specified artifact URL. |
| 126 | |
| 127 | 3. How to use: |
| 128 | |
| 129 | def tools = new ci.mcp.Tools() |
| 130 | ... |
| 131 | // |
| 132 | def artifact_url = "${env.ARTIFACTORY_URL}/api/storage/${repository}/${tag}" |
| 133 | def properties = tools.getPropertiesForArtifact(artifact_url) |
| 134 | |
| 135 | 4. Important notes: |
| 136 | |
| 137 | - will be returned LinkedHashMap of properties key-value pairs. Each value is an Array by default, |
| 138 | because each key can have few values. |
| 139 | - each key is available by get() method. |
| 140 | |
| 141 | |
| 142 | uploadImageToArtifactory |
| 143 | ------------------------ |
| 144 | |
| 145 | 1. uploadImageToArtifactory() should be used to upload Docker image to Artifactory. |
| 146 | |
| 147 | 2. How to use: |
| 148 | |
| 149 | def tools = new ci.mcp.Tools() |
| 150 | ... |
| 151 | // Docker registry for binaries and images |
| 152 | def docker_registry = 'ci.mcp-ci.local:5001' |
| 153 | def docker_image_name = 'hyperkube-amd64' |
| 154 | def docker_image_version = 'some_version' |
| 155 | def docker_repo = 'mcp-ci-local' |
| 156 | ... |
| 157 | <docker build steps> |
| 158 | ... |
| 159 | tools.uploadImageToArtifactory(docker_registry, docker_image_name, docker_image_version, docker_repo) |
| 160 | |
| 161 | 3. As a result specified image will be pushed to artifactory docker repo. |
| 162 | |
| 163 | |
| 164 | uploadBinariesToArtifactory |
| 165 | --------------------------- |
| 166 | |
| 167 | 1. uploadBinariesToArtifactory() should be used to upload binaries to Artifactory, like: |
| 168 | |
| 169 | - some executive binaries, which were built during job execution; |
| 170 | - *.yml files, etc. |
| 171 | |
| 172 | 2. How to use: |
| 173 | |
| 174 | def tools = new ci.mcp.Tools() |
| 175 | ... |
| 176 | def server = Artifactory.server('mcp-ci') |
| 177 | def buildInfo = Artifactory.BuildInfo() |
| 178 | ... |
| 179 | def uploadSpec = """{ |
| 180 | "files": [ |
| 181 | { |
| 182 | "pattern": "hyperkube*.yaml", |
| 183 | "target": "${artifactory_dev_repo}/images-info/" |
| 184 | }, |
| 185 | { |
| 186 | "pattern": "artifacts/hyperkube**", |
| 187 | "target": "${artifactory_dev_repo}/hyperkube-binaries/" |
| 188 | } |
| 189 | ] |
| 190 | }""" |
| 191 | tools.uploadBinariesToArtifactory(server, buildInfo, uploadSpec) |
| 192 | |
| 193 | |
| 194 | promoteDockerArtifact |
| 195 | --------------------- |
| 196 | |
| 197 | 1. promoteDockerArtifact() should be used to promote docker image to production repo, |
| 198 | because native promotion mechanism is not allow to do it due to Artifactory bug. |
| 199 | |
| 200 | 2. How to use: |
| 201 | |
| 202 | def tools = new ci.mcp.Tools() |
| 203 | ... |
| 204 | def artifactory_dev_repo = 'docker-local' |
| 205 | def artifactory_prod_repo = 'docker-prod' |
| 206 | def docker_repo = 'hyperkube-amd64' |
| 207 | ... |
| 208 | // functions above shall be used |
| 209 | <getting all tag's and artifact's information> |
| 210 | ... |
| 211 | def artifactImageTag = 'v1.4.0-XXXX' |
| 212 | def targetArtifactImageTag = 'v1.4.0' |
| 213 | ... |
| 214 | tools.promoteDockerArtifact(artifactory_dev_repo, |
| 215 | artifactory_prod_repo, |
| 216 | docker_repo, |
| 217 | artifactImageTag, |
| 218 | targetArtifactImageTag) |