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,15 @@ 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+ payload = {
241+ "payload_schema_version" : 3 if args .jobName else 2 ,
226242 "jenkins_env" : args .jenkinsEnv ,
227243 "build_id" : args .buildID ,
228244 "branch_name" : args .branchName ,
@@ -232,18 +248,23 @@ def build_pipeline_payload(design_records, args):
232248 "jenkins_url" : args .jenkinsURL ,
233249 "designs" : design_records ,
234250 }
251+ if args .jobName :
252+ payload ["job_name" ] = args .jobName
253+ return payload
235254
236255
237256def publish_pipeline_report (publisher , topic_path , message_data , design_count , args ):
238- """Publish a pre-encoded v2 pipeline message."""
257+ """Publish a pre-encoded pipeline message (v3 when --jobName is set, else v2) ."""
239258 size_kb = len (message_data ) / 1024
259+ schema_version = "3" if args .jobName else "2"
240260 print (
241- f"[INFO] Publishing pipeline report ({ design_count } designs, { size_kb :.1f} KB) to Pub/Sub."
261+ f"[INFO] Publishing v{ schema_version } pipeline report "
262+ f"({ design_count } designs, { size_kb :.1f} KB) to Pub/Sub."
242263 )
243264 future = publisher .publish (
244265 topic_path ,
245266 data = message_data ,
246- payload_schema_version = "2" ,
267+ payload_schema_version = schema_version ,
247268 jenkins_env = args .jenkinsEnv ,
248269 )
249270 message_id = future .result ()
0 commit comments