3535)
3636parser .add_argument ("--cred" , type = str , help = "Service account credentials file" )
3737parser .add_argument ("--variant" , type = str , default = "base" )
38+ parser .add_argument (
39+ "--jobName" ,
40+ type = str ,
41+ default = None ,
42+ help = "Canonical Jenkins job-folder name (JOB_NAME with the trailing "
43+ "/<branch> segment stripped, folder slashes kept). When set, the "
44+ "Pub/Sub payload is emitted as schema v3 with a top-level job_name "
45+ "so the backend resolves the pipeline directly instead of "
46+ "classifying the BUILD_TAG." ,
47+ )
3848
3949# --- PUBSUB args ---
4050parser .add_argument (
@@ -220,9 +230,16 @@ def build_design_record(dataFile, platform, design, variant, rules):
220230
221231
222232def build_pipeline_payload (design_records , args ):
223- """Return the v2 pipeline-level payload dict."""
224- return {
225- "payload_schema_version" : 2 ,
233+ """Return the pipeline-level payload dict.
234+
235+ Emits schema v3 (v2 structure plus a top-level ``job_name``) when
236+ ``--jobName`` is supplied; otherwise falls back to v2. The backend
237+ requires a non-blank ``job_name`` for v3, so an empty job name keeps
238+ the message on v2 and the legacy BUILD_TAG classifier.
239+ """
240+ job_name = args .jobName .strip () if args .jobName else None
241+ payload = {
242+ "payload_schema_version" : 3 if job_name else 2 ,
226243 "jenkins_env" : args .jenkinsEnv ,
227244 "build_id" : args .buildID ,
228245 "branch_name" : args .branchName ,
@@ -232,18 +249,24 @@ def build_pipeline_payload(design_records, args):
232249 "jenkins_url" : args .jenkinsURL ,
233250 "designs" : design_records ,
234251 }
252+ if job_name :
253+ payload ["job_name" ] = job_name
254+ return payload
235255
236256
237257def publish_pipeline_report (publisher , topic_path , message_data , design_count , args ):
238- """Publish a pre-encoded v2 pipeline message."""
258+ """Publish a pre-encoded pipeline message (v3 when --jobName is set, else v2) ."""
239259 size_kb = len (message_data ) / 1024
260+ job_name = args .jobName .strip () if args .jobName else None
261+ schema_version = "3" if job_name else "2"
240262 print (
241- f"[INFO] Publishing pipeline report ({ design_count } designs, { size_kb :.1f} KB) to Pub/Sub."
263+ f"[INFO] Publishing v{ schema_version } pipeline report "
264+ f"({ design_count } designs, { size_kb :.1f} KB) to Pub/Sub."
242265 )
243266 future = publisher .publish (
244267 topic_path ,
245268 data = message_data ,
246- payload_schema_version = "2" ,
269+ payload_schema_version = schema_version ,
247270 jenkins_env = args .jenkinsEnv ,
248271 )
249272 message_id = future .result ()
0 commit comments