{"record":{"id":"19a4689fdccdca19","repo":"theonedev/onedev","slug":"job-name-not-available-in-match-context","errorCode":null,"errorMessage":"Job name not available in match context","messagePattern":"Job name not available in match context","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/job/match/JobCriteria.java","lineNumber":36,"sourceCode":"\t\n\tprivate final String jobName;\n\t\n\tprivate final int operator;\n\t\n\tpublic JobCriteria(String jobName, int operator) {\n\t\tthis.jobName = jobName;\n\t\tthis.operator = operator;\n\t}\n\n\t@Override\n\tpublic boolean matches(JobMatchContext context) {\n\t\tif (context.getJobName() != null) {\n\t\t\tvar matches = WildcardUtils.matchString(jobName, context.getJobName());\n\t\t\tif (operator == JobMatchLexer.IsNot)\n\t\t\t\tmatches = !matches;\n\t\t\treturn matches;\n\t\t} else {\n\t\t\tthrow new ExplicitException(\"Job name not available in match context\");\n\t\t}\n\t}\n\n\t@Override\n\tpublic Predicate getPredicate(@Nullable ProjectScope projectScope, CriteriaQuery<?> query, From<JobMatchContext, JobMatchContext> from,\n\t\t\tCriteriaBuilder builder) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\t\n\t@Override\n\tpublic String toStringWithoutParens() {\n\t\treturn quote(Build.NAME_JOB) + \" \" \n\t\t\t\t+ JobMatch.getRuleName(operator) \n\t\t\t\t+ \" \" + quote(jobName);\n\t}\n\n}\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/job/match/JobCriteria.java#L18-L54","documentation":"Thrown by JobCriteria.matches when the JobMatchContext has a null job name, making a job-name criteria (e.g. 'job is xxx') unevaluable. Job match contexts built for secret authorization often only carry branch/commit, not job name. Thrown as ExplicitException.","triggerScenarios":"A job match expression using a job criteria (e.g. 'job is deploy') is evaluated against a context without a job name — typically during job secret authorization where JobMatchContext is constructed with null jobName.","commonSituations":"Using a 'job ...' condition in a job secret's authorization expression (which evaluates before the job name is known); copy-pasting build condition expressions into secret authorization; version changes in the match context surface.","solutions":["Remove the job criteria from the authorization/match expression — use branch or commit criteria instead","Use a criteria supported in that context (on branch, in project)","Move job-name-based secret selection to conditions evaluated with full job context","Split secrets per job if you need job-scoped authorization"],"exampleFix":"// before\n// authorization: \"job is deploy-job\"\n// after\n// authorization: \"on branch main\"","handlingStrategy":"validation","validationCode":"// only include job criteria in expressions evaluated with a full match context\n// use \"on branch ...\" / commit criteria in secret authorization expressions","typeGuard":null,"tryCatchPattern":"try {\n    jobMatch.matches(context);\n} catch (ExplicitException e) {\n    // expression uses job criteria but context has no job name; rewrite expression\n}","preventionTips":["Never use 'job ...' criteria in secret authorization expressions","Know which fields each match context provides","Prefer branch/commit criteria where job name is unavailable"],"tags":["ci","job-match","criteria","secrets"],"backgroundTag":"missing-required-argument","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}