blob: 2c4c1d56c6d3b310f95027f888b113ea67a3b9b4 [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
48uriByProperties
49---------------
50
511. uriByProperties() should be used to get URL for some artifact
52with specified properties, like:
53
54 "gerritChangeId=${env.GERRIT_CHANGE_ID}",
55 "gerritPatchsetNumber=${env.GERRIT_PATCHSET_NUMBER}"
56
572. Also can be used custom user' properties.
58
593. The resulting value will be the string in URL format, e.g:
60
61 "https://ci.mcp-ci.local/artifactory/mcp-k8s-ci/images-info/conformance_image_v1.4.1-5_1476965708283.yaml"
62
634. How to use:
64
65 def tools = new ci.mcp.Tools()
66 ...
67 def properties = ['com.mirantis.changeid': "${env.GERRIT_CHANGE_ID}",
68 'com.mirantis.patchset_number': "${env.GERRIT_PATCHSET_NUMBER}" ]
69 def artifact_uri = tools.uriByProperties(properties)
70
715. Important notes:
72
73 - if specified properties are set for few artifacts will be taken last.
74
75
76setProperties
77-------------
78
791. setProperties() should be used to set some properties to specified artifact in repo, like:
80
81 "gerritChangeId=${env.GERRIT_CHANGE_ID}",
82 "gerritPatchsetNumber=${env.GERRIT_PATCHSET_NUMBER}"
83
842. How to use:
85
86 def tools = new ci.mcp.Tools()
87 ...
88 def artifact_url = "${env.ARTIFACTORY_URL}/api/storage/${repository}/${tag}/${version}"
89 // for example: https://ci.mcp-ci.local/artifactory/api/storage/mcp-k8s-local/hyperkube-amd64/v1.4.1-5
90 def properties = ['com.mirantis.build_name':"${env.JOB_NAME}",
91 'com.mirantis.build_id': "${env.BUILD_NUMBER}",
92 'com.mirantis.changeid': "${env.GERRIT_CHANGE_ID}",
93 'com.mirantis.patchset_number': "${env.GERRIT_PATCHSET_NUMBER}"]
94
95 tools.setProperties(artifact_url, properties)
96
973. As result provided artifact in repo will be tagged by specified properties.
98
99
100getPropertiesForArtifact
101------------------------
102
1031. getPropertiesForArtifact() should be used to get properties for specified artifact in repo, like:
104
105 "https://ci.mcp-ci.local:443/artifactory/api/storage/mcp-k8s-ci/hyperkube-amd64/v1.4.1-5"
106
1072. As a result will be returned LinkedHashMap of properties for specified artifact URL.
108
1093. How to use:
110
111 def tools = new ci.mcp.Tools()
112 ...
113 //
114 def artifact_url = "${env.ARTIFACTORY_URL}/api/storage/${repository}/${tag}"
115 def properties = tools.getPropertiesForArtifact(artifact_url)
116
1174. Important notes:
118
119 - will be returned LinkedHashMap of properties key-value pairs. Each value is an Array by default,
120 because each key can have few values.
121 - each key is available by get() method.
122
123
124uploadImageToArtifactory
125------------------------
126
1271. uploadImageToArtifactory() should be used to upload Docker image to Artifactory.
128
1292. How to use:
130
131 def tools = new ci.mcp.Tools()
132 ...
133 // Docker registry for binaries and images
134 def docker_registry = 'ci.mcp-ci.local:5001'
135 def docker_image_name = 'hyperkube-amd64'
136 def docker_image_version = 'some_version'
137 def docker_repo = 'mcp-ci-local'
138 ...
139 <docker build steps>
140 ...
141 tools.uploadImageToArtifactory(docker_registry, docker_image_name, docker_image_version, docker_repo)
142
1433. As a result specified image will be pushed to artifactory docker repo.
144
145
146uploadBinariesToArtifactory
147---------------------------
148
1491. uploadBinariesToArtifactory() should be used to upload binaries to Artifactory, like:
150
151 - some executive binaries, which were built during job execution;
152 - *.yml files, etc.
153
1542. How to use:
155
156 def tools = new ci.mcp.Tools()
157 ...
158 def server = Artifactory.server('mcp-ci')
159 def buildInfo = Artifactory.BuildInfo()
160 ...
161 def uploadSpec = """{
162 "files": [
163 {
164 "pattern": "hyperkube*.yaml",
165 "target": "${artifactory_dev_repo}/images-info/"
166 },
167 {
168 "pattern": "artifacts/hyperkube**",
169 "target": "${artifactory_dev_repo}/hyperkube-binaries/"
170 }
171 ]
172 }"""
173 tools.uploadBinariesToArtifactory(server, buildInfo, uploadSpec)
174
175
176promoteDockerArtifact
177---------------------
178
1791. promoteDockerArtifact() should be used to promote docker image to production repo,
180because native promotion mechanism is not allow to do it due to Artifactory bug.
181
1822. How to use:
183
184 def tools = new ci.mcp.Tools()
185 ...
186 def artifactory_dev_repo = 'docker-local'
187 def artifactory_prod_repo = 'docker-prod'
188 def docker_repo = 'hyperkube-amd64'
189 ...
190 // functions above shall be used
191 <getting all tag's and artifact's information>
192 ...
193 def artifactImageTag = 'v1.4.0-XXXX'
194 def targetArtifactImageTag = 'v1.4.0'
195 ...
196 tools.promoteDockerArtifact(artifactory_dev_repo,
197 artifactory_prod_repo,
198 docker_repo,
199 artifactImageTag,
200 targetArtifactImageTag)