36
36
import hudson .plugins .git .extensions .GitSCMExtensionDescriptor ;
37
37
import hudson .plugins .git .extensions .impl .AuthorInChangelog ;
38
38
import hudson .plugins .git .extensions .impl .BuildChooserSetting ;
39
+ import hudson .plugins .git .extensions .impl .BuildSingleRevisionOnly ;
40
+ import hudson .plugins .git .extensions .impl .ChangelogToBranch ;
39
41
import hudson .plugins .git .extensions .impl .PathRestriction ;
40
42
import hudson .plugins .git .extensions .impl .LocalBranch ;
41
43
import hudson .plugins .git .extensions .impl .RelativeTargetDirectory ;
76
78
import org .jenkinsci .plugins .gitclient .FetchCommand ;
77
79
import org .jenkinsci .plugins .gitclient .Git ;
78
80
import org .jenkinsci .plugins .gitclient .GitClient ;
81
+ import org .jenkinsci .plugins .scriptsecurity .sandbox .whitelists .Whitelisted ;
79
82
import org .kohsuke .stapler .DataBoundConstructor ;
80
83
import org .kohsuke .stapler .StaplerRequest ;
81
84
import org .kohsuke .stapler .export .Exported ;
@@ -164,6 +167,7 @@ public class GitSCM extends GitSCMBackwardCompatibility {
164
167
@ SuppressFBWarnings (value ="SE_BAD_FIELD" , justification ="Known non-serializable field" )
165
168
private DescribableList <GitSCMExtension ,GitSCMExtensionDescriptor > extensions ;
166
169
170
+ @ Whitelisted
167
171
public Collection <SubmoduleConfig > getSubmoduleCfg () {
168
172
return submoduleCfg ;
169
173
}
@@ -239,6 +243,7 @@ public GitSCM(
239
243
*
240
244
* @since 2.0
241
245
*/
246
+ @ Whitelisted
242
247
public DescribableList <GitSCMExtension , GitSCMExtensionDescriptor > getExtensions () {
243
248
return extensions ;
244
249
}
@@ -350,6 +355,7 @@ public Object readResolve() throws IOException {
350
355
}
351
356
352
357
@ Override
358
+ @ Whitelisted
353
359
public GitRepositoryBrowser getBrowser () {
354
360
return browser ;
355
361
}
@@ -432,6 +438,7 @@ public boolean isUseExistingAccountWithSameEmail() {
432
438
return (gitDescriptor != null && gitDescriptor .isUseExistingAccountWithSameEmail ());
433
439
}
434
440
441
+ @ Whitelisted
435
442
public BuildChooser getBuildChooser () {
436
443
BuildChooser bc ;
437
444
@@ -521,6 +528,7 @@ public RemoteConfig getRepositoryByName(String repoName) {
521
528
}
522
529
523
530
@ Exported
531
+ @ Whitelisted
524
532
public List <UserRemoteConfig > getUserRemoteConfigs () {
525
533
if (userRemoteConfigs == null ) {
526
534
/* Prevent NPE when no remote config defined */
@@ -529,6 +537,7 @@ public List<UserRemoteConfig> getUserRemoteConfigs() {
529
537
return Collections .unmodifiableList (userRemoteConfigs );
530
538
}
531
539
540
+ @ Whitelisted
532
541
public List <RemoteConfig > getRepositories () {
533
542
// Handle null-value to ensure backwards-compatibility, ie project configuration missing the <repositories/> XML element
534
543
if (remoteRepositories == null ) {
@@ -573,6 +582,7 @@ public String deriveLocalBranchName(String remoteBranchName) {
573
582
}
574
583
575
584
@ CheckForNull
585
+ @ Whitelisted
576
586
public String getGitTool () {
577
587
return gitTool ;
578
588
}
@@ -1062,17 +1072,24 @@ public EnvVars getEnvironment() {
1062
1072
if (buildData .getBuildsByBranchName ().size () >= 100 ) {
1063
1073
log .println ("JENKINS-19022: warning: possible memory leak due to Git plugin usage; see: https://wiki.jenkins.io/display/JENKINS/Remove+Git+Plugin+BuildsByBranch+BuildData" );
1064
1074
}
1075
+ boolean checkForMultipleRevisions = true ;
1076
+ BuildSingleRevisionOnly ext = extensions .get (BuildSingleRevisionOnly .class );
1077
+ if (ext != null ) {
1078
+ checkForMultipleRevisions = ext .enableMultipleRevisionDetection ();
1079
+ }
1065
1080
1066
1081
if (candidates .size () > 1 ) {
1067
1082
log .println ("Multiple candidate revisions" );
1068
- Job <?, ?> job = build .getParent ();
1069
- if (job instanceof AbstractProject ) {
1070
- AbstractProject project = (AbstractProject ) job ;
1071
- if (!project .isDisabled ()) {
1072
- log .println ("Scheduling another build to catch up with " + project .getFullDisplayName ());
1073
- if (!project .scheduleBuild (0 , new SCMTrigger .SCMTriggerCause ("This build was triggered by build "
1074
- + build .getNumber () + " because more than one build candidate was found." ))) {
1075
- log .println ("WARNING: multiple candidate revisions, but unable to schedule build of " + project .getFullDisplayName ());
1083
+ if (checkForMultipleRevisions ) {
1084
+ Job <?, ?> job = build .getParent ();
1085
+ if (job instanceof AbstractProject ) {
1086
+ AbstractProject project = (AbstractProject ) job ;
1087
+ if (!project .isDisabled ()) {
1088
+ log .println ("Scheduling another build to catch up with " + project .getFullDisplayName ());
1089
+ if (!project .scheduleBuild (0 , new SCMTrigger .SCMTriggerCause ("This build was triggered by build "
1090
+ + build .getNumber () + " because more than one build candidate was found." ))) {
1091
+ log .println ("WARNING: multiple candidate revisions, but unable to schedule build of " + project .getFullDisplayName ());
1092
+ }
1076
1093
}
1077
1094
}
1078
1095
}
@@ -1363,6 +1380,16 @@ public void buildEnvironment(Run<?, ?> build, java.util.Map<String, String> env)
1363
1380
}
1364
1381
}
1365
1382
1383
+ /* Check all repository URLs are not empty */
1384
+ /* JENKINS-38608 reports an unhelpful error message when a repository URL is empty */
1385
+ /* Throws an IllegalArgumentException because that exception is thrown by env.put() on a null argument */
1386
+ int repoCount = 1 ;
1387
+ for (UserRemoteConfig config :userRemoteConfigs ) {
1388
+ if (config .getUrl () == null ) {
1389
+ throw new IllegalArgumentException ("Git repository URL " + repoCount + " is an empty string in job definition. Checkout requires a valid repository URL" );
1390
+ }
1391
+ repoCount ++;
1392
+ }
1366
1393
1367
1394
if (userRemoteConfigs .size ()==1 ){
1368
1395
env .put ("GIT_URL" , userRemoteConfigs .get (0 ).getUrl ());
@@ -1689,11 +1716,13 @@ public void populateEnvironmentVariables(Map<String,String> env) {
1689
1716
1690
1717
private static final long serialVersionUID = 1L ;
1691
1718
1719
+ @ Whitelisted
1692
1720
public boolean isDoGenerateSubmoduleConfigurations () {
1693
1721
return this .doGenerateSubmoduleConfigurations ;
1694
1722
}
1695
1723
1696
1724
@ Exported
1725
+ @ Whitelisted
1697
1726
public List <BranchSpec > getBranches () {
1698
1727
return branches ;
1699
1728
}
0 commit comments