This repository was archived by the owner on Oct 15, 2024. It is now read-only.
File tree 2 files changed +18
-9
lines changed
src/main/java/io/jenkins/plugins/security/scan
2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change 1
1
package io .jenkins .plugins .security .scan .global ;
2
2
3
+ import com .cloudbees .hudson .plugins .folder .Folder ;
3
4
import hudson .EnvVars ;
4
5
import hudson .FilePath ;
5
6
import hudson .model .Result ;
@@ -202,13 +203,24 @@ public static String jenkinsJobType(EnvVars envVars) {
202
203
Jenkins jenkins = Jenkins .getInstanceOrNull ();
203
204
204
205
String jobName = envVars .get (ApplicationConstants .ENV_JOB_NAME_KEY );
205
- String finalJobName =
206
- jobName != null ? jobName .contains ("/" ) ? jobName .substring (0 , jobName .indexOf ('/' )) : jobName : null ;
207
206
208
- TopLevelItem job = jenkins != null ? jenkins .getItem (finalJobName ) : null ;
207
+ // Extract the part before the last '/' for potential multibranch projects
208
+ String jobNameForMultibranchProject = jobName != null
209
+ ? jobName .contains ("/" ) ? jobName .substring (0 , jobName .lastIndexOf ('/' )) : jobName
210
+ : null ;
209
211
210
- if (job != null ) {
211
- return job .getClass ().getSimpleName ();
212
+ // If item is not a 'Folder', then it is a Multibranch pipeline job
213
+ TopLevelItem item =
214
+ jenkins != null ? jenkins .getItemByFullName (jobNameForMultibranchProject , TopLevelItem .class ) : null ;
215
+
216
+ // If 'item' is an instanceof 'Folder', it is either 'WorkflowJob' or 'FreestyleJob'
217
+ // Then try to get the item type with actual 'jobName'
218
+ if (item instanceof Folder ) {
219
+ item = jenkins != null ? jenkins .getItemByFullName (jobName , TopLevelItem .class ) : null ;
220
+ }
221
+
222
+ if (item != null ) {
223
+ return item .getClass ().getSimpleName ();
212
224
} else {
213
225
return "UnknownJobType" ;
214
226
}
Original file line number Diff line number Diff line change @@ -79,10 +79,7 @@ public Object fetchSCMRepositoryDetails(
79
79
80
80
public SCMSource findSCMSource () {
81
81
String jobName = envVars .get (ApplicationConstants .ENV_JOB_NAME_KEY );
82
- if (jobName == null || !jobName .contains ("/" )) {
83
- return null ;
84
- }
85
- jobName = jobName .substring (0 , jobName .indexOf ("/" ));
82
+ jobName = jobName .contains ("/" ) ? jobName .substring (0 , jobName .lastIndexOf ('/' )) : jobName ;
86
83
logger .info ("Jenkins Job name: " + jobName );
87
84
88
85
Jenkins jenkins = Jenkins .getInstanceOrNull ();
You can’t perform that action at this time.
0 commit comments