Debian Codegraph @

jenkins_jobs/modules/zuul.py

raw
1 # Copyright 2012 Hewlett-Packard Development Company, L.P.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 """
16 The Zuul module adds jobs parameters to manually run a build as Zuul would
17 have. It is entirely optional, Zuul 2.0+ pass the parameters over Gearman.
18
19 .. _expected by Zuul: \
20 https://opendev.org/zuul/zuul/src/tag/2.6.0/doc/source/launchers.rst#user-content-zuul-parameters
21 """
22
23 import jenkins_jobs.modules.base
24
25
26 def zuul():
27 """yaml: zuul
28 Configure this job to be triggered by Zuul.
29
30 Adds parameters describing the change triggering the build such as the
31 branch name, change number and patchset.
32
33 See parameters `expected by Zuul`_.
34
35 Example::
36
37 triggers:
38 - zuul
39 """
40
41
42 def zuul_post():
43 """yaml: zuul-post
44 Configure this post-merge job to be triggered by Zuul.
45
46 Adds parameters describing the reference update triggering the build, which
47 are the previous and next revisions in full (40 hexadecimal sha1) and short
48 form.
49
50 See parameters `expected by Zuul`_.
51
52 Example::
53
54 triggers:
55 - zuul-post
56 """
57
58
59 ZUUL_PARAMETERS = [
60 {
61 "string": {
62 "description": "Zuul provided key to link builds with Gerrit events",
63 "name": "ZUUL_UUID",
64 }
65 },
66 {
67 "string": {
68 "description": "Zuul provided key to link builds with Gerrit"
69 " events (deprecated use ZUUL_UUID instead)",
70 "name": "UUID",
71 }
72 },
73 {
74 "string": {
75 "description": "Zuul pipeline triggering this job",
76 "name": "ZUUL_PIPELINE",
77 }
78 },
79 {
80 "string": {
81 "description": "URL of Zuul's git repos accessible to workers",
82 "name": "ZUUL_URL",
83 }
84 },
85 {
86 "string": {
87 "description": "Branch name of triggering project",
88 "name": "ZUUL_PROJECT",
89 }
90 },
91 {
92 "string": {
93 "description": "Branch name of triggering change",
94 "name": "ZUUL_BRANCH",
95 }
96 },
97 {
98 "string": {
99 "description": "List of dependent changes to merge",
100 "name": "ZUUL_CHANGES",
101 }
102 },
103 {
104 "string": {
105 "description": "Reference for the merged commit(s) to use",
106 "name": "ZUUL_REF",
107 }
108 },
109 {
110 "string": {
111 "description": "The commit SHA1 at the head of ZUUL_REF",
112 "name": "ZUUL_COMMIT",
113 }
114 },
115 {"string": {"description": "List of included changes", "name": "ZUUL_CHANGE_IDS"}},
116 {"string": {"description": "ID of triggering change", "name": "ZUUL_CHANGE"}},
117 {
118 "string": {
119 "description": "Patchset of triggering change",
120 "name": "ZUUL_PATCHSET",
121 }
122 },
123 {
124 "string": {
125 "description": "Zuul considered this job voting or not",
126 "name": "ZUUL_VOTING",
127 }
128 },
129 ]
130
131 ZUUL_POST_PARAMETERS = [
132 {
133 "string": {
134 "description": "Zuul provided key to link builds with Gerrit events",
135 "name": "ZUUL_UUID",
136 }
137 },
138 {
139 "string": {
140 "description": "Zuul provided key to link builds with Gerrit"
141 " events (deprecated use ZUUL_UUID instead)",
142 "name": "UUID",
143 }
144 },
145 {
146 "string": {
147 "description": "Zuul pipeline triggering this job",
148 "name": "ZUUL_PIPELINE",
149 }
150 },
151 {
152 "string": {
153 "description": "URL of Zuul's git repos accessible to workers",
154 "name": "ZUUL_URL",
155 }
156 },
157 {
158 "string": {
159 "description": "Branch name of triggering project",
160 "name": "ZUUL_PROJECT",
161 }
162 },
163 {
164 "string": {
165 "description": "Name of updated reference triggering this job",
166 "name": "ZUUL_REF",
167 }
168 },
169 {
170 "string": {
171 "description": "Name of updated reference triggering this job",
172 "name": "ZUUL_REFNAME",
173 }
174 },
175 {"string": {"description": "Old SHA at this reference", "name": "ZUUL_OLDREV"}},
176 {"string": {"description": "New SHA at this reference", "name": "ZUUL_NEWREV"}},
177 {
178 "string": {
179 "description": "Shortened new SHA at this reference",
180 "name": "ZUUL_SHORT_NEWREV",
181 }
182 },
183 ]
184
185
186 class Zuul(jenkins_jobs.modules.base.Base):
187 sequence = 0
188
189 def amend_job_dict(self, job):
190 triggers = job.get("triggers", [])
191 if "zuul" not in triggers and "zuul-post" not in triggers:
192 return False
193
194 parameters = job.setdefault("parameters", [])
195 if "zuul" in triggers:
196 parameters.extend(ZUUL_PARAMETERS)
197 triggers.remove("zuul")
198 if "zuul-post" in triggers:
199 parameters.extend(ZUUL_POST_PARAMETERS)
200 triggers.remove("zuul-post")
201 return True