Skip to content

Commit 3ae23bf

Browse files
authored
fix(jenkins): incorrect class type on multibranch jobs (#7464)
* fix(jenkins): check for correct class type The input for builds is a workflow job and not a workflow multibranch project. * fix(jenkins): add tests to multibranch flow
1 parent 153f7b9 commit 3ae23bf

11 files changed

+429
-272
lines changed
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package e2e
19+
20+
import (
21+
"testing"
22+
23+
"github.com/apache/incubator-devlake/core/models/common"
24+
"github.com/apache/incubator-devlake/core/models/domainlayer/devops"
25+
26+
"github.com/apache/incubator-devlake/helpers/e2ehelper"
27+
"github.com/apache/incubator-devlake/plugins/jenkins/impl"
28+
"github.com/apache/incubator-devlake/plugins/jenkins/models"
29+
"github.com/apache/incubator-devlake/plugins/jenkins/tasks"
30+
31+
api "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
32+
)
33+
34+
func TestJenkinsMultibranchDataFlow(t *testing.T) {
35+
var jenkins impl.Jenkins
36+
dataflowTester := e2ehelper.NewDataFlowTester(t, "jenkins", jenkins)
37+
38+
regexEnricher := api.NewRegexEnricher()
39+
_ = regexEnricher.TryAdd(devops.DEPLOYMENT, `test-sub-sub-dir\/devlake.*`)
40+
taskData := &tasks.JenkinsTaskData{
41+
Options: &tasks.JenkinsOptions{
42+
ConnectionId: 1,
43+
JobName: `devlake-jenkins`,
44+
JobFullName: `github_org/devlake-jenkins`,
45+
JobPath: ``,
46+
Class: `org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject`,
47+
ScopeConfig: new(models.JenkinsScopeConfig),
48+
},
49+
Connection: &models.JenkinsConnection{
50+
JenkinsConn: models.JenkinsConn{
51+
RestConnection: api.RestConnection{
52+
Endpoint: "https://1457-62-195-68-26.ngrok-free.app",
53+
},
54+
},
55+
},
56+
RegexEnricher: regexEnricher,
57+
}
58+
59+
// This replaces tasks.CollectApiJobsMeta
60+
dataflowTester.FlushTabler(&models.JenkinsJob{})
61+
dataflowTester.ImportCsvIntoRawTable("./raw_tables/_raw_jenkins_api_jobs_multibranch.csv", "_raw_jenkins_api_jobs")
62+
63+
dataflowTester.Subtask(tasks.ExtractApiJobsMeta, taskData)
64+
dataflowTester.VerifyTableWithOptions(&models.JenkinsJob{}, e2ehelper.TableOptions{
65+
CSVRelPath: "./raw_tables/_tool_jenkins_jobs_multibranch.csv",
66+
IgnoreTypes: []interface{}{common.NoPKModel{}},
67+
})
68+
69+
dataflowTester.FlushTabler(&devops.CicdScope{})
70+
dataflowTester.Subtask(tasks.ConvertJobsMeta, taskData)
71+
dataflowTester.VerifyTableWithOptions(&devops.CicdScope{}, e2ehelper.TableOptions{
72+
CSVRelPath: "./snapshot_tables/cicd_scopes_multibranch.csv",
73+
IgnoreTypes: []interface{}{common.NoPKModel{}},
74+
})
75+
76+
// This replaces tasks.CollectApiBuildsMeta
77+
dataflowTester.FlushTabler(&models.JenkinsBuild{})
78+
dataflowTester.FlushTabler(&models.JenkinsBuildCommit{})
79+
dataflowTester.ImportCsvIntoRawTable("./raw_tables/_raw_jenkins_api_builds_multibranch.csv", "_raw_jenkins_api_builds")
80+
81+
dataflowTester.Subtask(tasks.ExtractApiBuildsMeta, taskData)
82+
dataflowTester.VerifyTable(
83+
models.JenkinsBuild{},
84+
"./snapshot_tables/_tool_jenkins_builds_multibranch.csv",
85+
e2ehelper.ColumnWithRawData(
86+
"connection_id",
87+
"job_name",
88+
"job_path",
89+
"duration",
90+
"full_name",
91+
"estimated_duration",
92+
"number",
93+
"result",
94+
"timestamp",
95+
"start_time",
96+
"has_stages",
97+
),
98+
)
99+
dataflowTester.VerifyTable(
100+
models.JenkinsBuildCommit{},
101+
"./snapshot_tables/_tool_jenkins_build_commits_multibranch.csv",
102+
e2ehelper.ColumnWithRawData(
103+
"connection_id",
104+
"build_name",
105+
"commit_sha",
106+
"branch",
107+
"repo_url",
108+
),
109+
)
110+
111+
// This replaces tasks.CollectApiStagesMeta
112+
dataflowTester.FlushRawTable("_raw_jenkins_api_stages")
113+
dataflowTester.ImportCsvIntoRawTable("./raw_tables/_raw_jenkins_api_stages_multibranch.csv", "_raw_jenkins_api_stages")
114+
115+
dataflowTester.FlushTabler(&models.JenkinsStage{})
116+
dataflowTester.Subtask(tasks.ExtractApiStagesMeta, taskData)
117+
dataflowTester.VerifyTable(
118+
models.JenkinsStage{},
119+
"./snapshot_tables/_tool_jenkins_stages_multibranch.csv",
120+
e2ehelper.ColumnWithRawData(
121+
"connection_id",
122+
"id",
123+
"build_name",
124+
"name",
125+
"exec_node",
126+
"status",
127+
"start_time_millis",
128+
"duration_millis",
129+
"pause_duration_millis",
130+
"type",
131+
),
132+
)
133+
134+
dataflowTester.Subtask(tasks.EnrichApiBuildWithStagesMeta, taskData)
135+
dataflowTester.VerifyTable(
136+
models.JenkinsBuild{},
137+
"./snapshot_tables/_tool_jenkins_builds_multibranch_after_enrich.csv",
138+
e2ehelper.ColumnWithRawData(
139+
"connection_id",
140+
"job_name",
141+
"job_path",
142+
"duration",
143+
"full_name",
144+
"estimated_duration",
145+
"number",
146+
"result",
147+
"timestamp",
148+
"start_time",
149+
"has_stages",
150+
),
151+
)
152+
153+
dataflowTester.FlushTabler(&devops.CICDTask{})
154+
dataflowTester.FlushTabler(&devops.CICDPipeline{})
155+
dataflowTester.FlushTabler(&devops.CiCDPipelineCommit{})
156+
157+
dataflowTester.Subtask(tasks.ConvertBuildsToCicdTasksMeta, taskData)
158+
dataflowTester.VerifyTable(
159+
devops.CICDTask{},
160+
"./snapshot_tables/cicd_tasks_multibranch.csv",
161+
e2ehelper.ColumnWithRawData(
162+
"name",
163+
"pipeline_id",
164+
"result",
165+
"status",
166+
"original_result",
167+
"original_status",
168+
"type",
169+
"environment",
170+
"duration_sec",
171+
"started_date",
172+
"finished_date",
173+
"cicd_scope_id",
174+
),
175+
)
176+
dataflowTester.VerifyTable(
177+
devops.CICDPipeline{},
178+
"./snapshot_tables/cicd_pipelines_multibranch.csv",
179+
e2ehelper.ColumnWithRawData(
180+
"name",
181+
"result",
182+
"status",
183+
"original_result",
184+
"original_status",
185+
"type",
186+
"duration_sec",
187+
"environment",
188+
"created_date",
189+
"finished_date",
190+
"cicd_scope_id",
191+
),
192+
)
193+
dataflowTester.Subtask(tasks.ConvertBuildReposMeta, taskData)
194+
dataflowTester.VerifyTable(
195+
devops.CiCDPipelineCommit{},
196+
"./snapshot_tables/cicd_pipeline_commits_multibranch.csv",
197+
e2ehelper.ColumnWithRawData(
198+
"pipeline_id",
199+
"repo_id",
200+
"repo_url",
201+
"branch",
202+
"commit_sha",
203+
),
204+
)
205+
206+
}

0 commit comments

Comments
 (0)