Skip to content

Commit 70ef083

Browse files
KyriosGN0claude
authored andcommitted
fix(jenkins): scope multi-branch build collection to current project (#8430) (#8781)
The branch jobs query in collectMultiBranchJobApiBuilds selected all WorkflowJob entries across all multi-branch pipelines for a connection, causing builds to be duplicated and misattributed. Filter by _raw_data_params to collect only the current project's branch jobs. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ba7add5 commit 70ef083

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

backend/plugins/jenkins/tasks/build_collector.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,17 @@ func collectMultiBranchJobApiBuilds(taskCtx plugin.SubTaskContext) errors.Error
146146
logger := taskCtx.GetLogger()
147147

148148
// Jobs added through the multi-branch workflow have _raw_data_table set to "jenkins_api_jobs".
149-
// This check works, but it's not very robust. It would be better to use a more explicit check like a "source" column.
149+
// Filter by _raw_data_params to scope to only this multi-branch project's branch jobs,
150+
// preventing cross-project data mixing when multiple multi-branch pipelines exist.
151+
jobParams := plugin.MarshalScopeParams(JenkinsApiParams{
152+
ConnectionId: data.Options.ConnectionId,
153+
FullName: data.Options.JobFullName,
154+
})
150155
clauses := []dal.Clause{
151156
dal.Select("j.full_name,j.name,j.path,j.class,j.url"),
152157
dal.From("_tool_jenkins_jobs as j"),
153-
dal.Where(`j.connection_id = ? and j.class = ? and j._raw_data_table = ?`,
154-
data.Options.ConnectionId, WORKFLOW_JOB, fmt.Sprintf("_raw_%s", RAW_JOB_TABLE)),
158+
dal.Where(`j.connection_id = ? and j.class = ? and j._raw_data_table = ? and j._raw_data_params = ?`,
159+
data.Options.ConnectionId, WORKFLOW_JOB, fmt.Sprintf("_raw_%s", RAW_JOB_TABLE), jobParams),
155160
}
156161
cursor, err := db.Cursor(clauses...)
157162
if err != nil {

0 commit comments

Comments
 (0)