blob: 8229970b6ebcf839cd8b70ebade9350ed0b82e5a [file] [log] [blame]
Sergey Kulanov56d0d052016-10-13 15:48:56 +03001getBinaryBuildProperties
2------------------------
3
41. getBinaryBuildProperties() should be used to define mandatory
5properties 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
132. User can add some custom properties, e.g:
14
15def properties = tools.getBinaryBuildProperties(
16 ["test=123",
17 "prop1=val1",
18 prop2=val2"
19 ])
20
213. The resulting values will be the string in props format with
22namespace com.mirantis, e.g:
23
24 com.mirantis.gerritProject=asd;com.mirantis.gerritChangeNumber=123;com.mirantis.gerritChangeId=ddd
25
264. 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 Egorenkoe3552682016-10-18 13:29:29 +030046
47
Sergey Kulanov20c8b132016-11-02 13:24:32 +020048setDockerfileLabels
49-------------------
50// simple usage, which adds mandatory properties to Dockerfile which is
51// located in current directory
52tools.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 Egorenkoe3552682016-10-18 13:29:29 +030066uriByProperties
67---------------
68
691. uriByProperties() should be used to get URL for some artifact
70with specified properties, like:
71
72 "gerritChangeId=${env.GERRIT_CHANGE_ID}",
73 "gerritPatchsetNumber=${env.GERRIT_PATCHSET_NUMBER}"
74
752. Also can be used custom user' properties.
76
773. 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
814. 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
895. Important notes:
90
91 - if specified properties are set for few artifacts will be taken last.
92
93
94setProperties
95-------------
96
971. 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
1022. 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
1153. As result provided artifact in repo will be tagged by specified properties.
116
117
118getPropertiesForArtifact
119------------------------
120
1211. 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
1252. As a result will be returned LinkedHashMap of properties for specified artifact URL.
126
1273. 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
1354. 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
142uploadImageToArtifactory
143------------------------
144
1451. uploadImageToArtifactory() should be used to upload Docker image to Artifactory.
146
1472. 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
1613. As a result specified image will be pushed to artifactory docker repo.
162
163
164uploadBinariesToArtifactory
165---------------------------
166
1671. 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
1722. 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
194promoteDockerArtifact
195---------------------
196
1971. promoteDockerArtifact() should be used to promote docker image to production repo,
198because native promotion mechanism is not allow to do it due to Artifactory bug.
199
2002. 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)