Skip to content

Commit

Permalink
Merge branch 'master' into feature/JENKINS-56284
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEWaite committed Mar 10, 2020
2 parents 5baf418 + ead9a34 commit 1916bf9
Show file tree
Hide file tree
Showing 35 changed files with 1,335 additions and 114 deletions.
458 changes: 408 additions & 50 deletions README.adoc

Large diffs are not rendered by default.

56 changes: 40 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.55</version>
<version>3.57</version>
<relativePath />
</parent>

Expand All @@ -20,27 +20,28 @@
<version>${revision}${changelist}</version>
<packaging>hpi</packaging>
<name>Jenkins Git plugin</name>
<description>Integrates Jenkins with GIT SCM</description>
<url>https://github.com/jenkinsci/git-plugin/README.adoc</url>
<description>Integrates Jenkins with Git SCM</description>
<url>https://github.com/jenkinsci/git-plugin/blob/master/README.adoc</url>
<inceptionYear>2007</inceptionYear>

<properties>
<revision>4.1.0</revision>
<revision>4.3.0</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.138.4</jenkins.version>
<java.level>8</java.level>
<no-test-jar>false</no-test-jar>
<useBeta>true</useBeta>
<forkCount>1</forkCount>
<forkCount>3</forkCount>
<linkXRef>false</linkXRef>
<configuration-as-code.version>1.35</configuration-as-code.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<failOnViolation>true</failOnViolation>
Expand Down Expand Up @@ -97,6 +98,10 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
Expand All @@ -120,11 +125,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
Expand All @@ -139,7 +139,7 @@
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.1.11</version>
<version>3.1.12</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -204,11 +204,17 @@
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps-global-lib</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
<version>2.6.3</version>
<version>2.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -227,13 +233,20 @@
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>${configuration-as-code.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<classifier>tests</classifier>
<groupId>io.jenkins.configuration-as-code</groupId>
<artifactId>test-harness</artifactId>
<version>${configuration-as-code.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Exclude JTH dependency commons-net - otherwise it is included in hpi file as a transient dependency -->
<dependency>
Expand All @@ -247,6 +260,17 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
<exclusions>
<exclusion>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/hudson/plugins/git/BranchSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

Expand All @@ -38,6 +39,7 @@ public class BranchSpec extends AbstractDescribableImpl<BranchSpec> implements S
private String name;

@Exported
@Whitelisted
public String getName() {
return name;
}
Expand Down
45 changes: 37 additions & 8 deletions src/main/java/hudson/plugins/git/GitSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
import hudson.plugins.git.extensions.impl.AuthorInChangelog;
import hudson.plugins.git.extensions.impl.BuildChooserSetting;
import hudson.plugins.git.extensions.impl.BuildSingleRevisionOnly;
import hudson.plugins.git.extensions.impl.ChangelogToBranch;
import hudson.plugins.git.extensions.impl.PathRestriction;
import hudson.plugins.git.extensions.impl.LocalBranch;
import hudson.plugins.git.extensions.impl.RelativeTargetDirectory;
Expand Down Expand Up @@ -76,6 +78,7 @@
import org.jenkinsci.plugins.gitclient.FetchCommand;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.export.Exported;
Expand Down Expand Up @@ -164,6 +167,7 @@ public class GitSCM extends GitSCMBackwardCompatibility {
@SuppressFBWarnings(value="SE_BAD_FIELD", justification="Known non-serializable field")
private DescribableList<GitSCMExtension,GitSCMExtensionDescriptor> extensions;

@Whitelisted
public Collection<SubmoduleConfig> getSubmoduleCfg() {
return submoduleCfg;
}
Expand Down Expand Up @@ -239,6 +243,7 @@ public GitSCM(
*
* @since 2.0
*/
@Whitelisted
public DescribableList<GitSCMExtension, GitSCMExtensionDescriptor> getExtensions() {
return extensions;
}
Expand Down Expand Up @@ -350,6 +355,7 @@ public Object readResolve() throws IOException {
}

@Override
@Whitelisted
public GitRepositoryBrowser getBrowser() {
return browser;
}
Expand Down Expand Up @@ -432,6 +438,7 @@ public boolean isUseExistingAccountWithSameEmail() {
return (gitDescriptor != null && gitDescriptor.isUseExistingAccountWithSameEmail());
}

@Whitelisted
public BuildChooser getBuildChooser() {
BuildChooser bc;

Expand Down Expand Up @@ -521,6 +528,7 @@ public RemoteConfig getRepositoryByName(String repoName) {
}

@Exported
@Whitelisted
public List<UserRemoteConfig> getUserRemoteConfigs() {
if (userRemoteConfigs == null) {
/* Prevent NPE when no remote config defined */
Expand All @@ -529,6 +537,7 @@ public List<UserRemoteConfig> getUserRemoteConfigs() {
return Collections.unmodifiableList(userRemoteConfigs);
}

@Whitelisted
public List<RemoteConfig> getRepositories() {
// Handle null-value to ensure backwards-compatibility, ie project configuration missing the <repositories/> XML element
if (remoteRepositories == null) {
Expand Down Expand Up @@ -573,6 +582,7 @@ public String deriveLocalBranchName(String remoteBranchName) {
}

@CheckForNull
@Whitelisted
public String getGitTool() {
return gitTool;
}
Expand Down Expand Up @@ -1062,17 +1072,24 @@ public EnvVars getEnvironment() {
if (buildData.getBuildsByBranchName().size() >= 100) {
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");
}
boolean checkForMultipleRevisions = true;
BuildSingleRevisionOnly ext = extensions.get(BuildSingleRevisionOnly.class);
if (ext != null) {
checkForMultipleRevisions = ext.enableMultipleRevisionDetection();
}

if (candidates.size() > 1) {
log.println("Multiple candidate revisions");
Job<?, ?> job = build.getParent();
if (job instanceof AbstractProject) {
AbstractProject project = (AbstractProject) job;
if (!project.isDisabled()) {
log.println("Scheduling another build to catch up with " + project.getFullDisplayName());
if (!project.scheduleBuild(0, new SCMTrigger.SCMTriggerCause("This build was triggered by build "
+ build.getNumber() + " because more than one build candidate was found."))) {
log.println("WARNING: multiple candidate revisions, but unable to schedule build of " + project.getFullDisplayName());
if (checkForMultipleRevisions) {
Job<?, ?> job = build.getParent();
if (job instanceof AbstractProject) {
AbstractProject project = (AbstractProject) job;
if (!project.isDisabled()) {
log.println("Scheduling another build to catch up with " + project.getFullDisplayName());
if (!project.scheduleBuild(0, new SCMTrigger.SCMTriggerCause("This build was triggered by build "
+ build.getNumber() + " because more than one build candidate was found."))) {
log.println("WARNING: multiple candidate revisions, but unable to schedule build of " + project.getFullDisplayName());
}
}
}
}
Expand Down Expand Up @@ -1363,6 +1380,16 @@ public void buildEnvironment(Run<?, ?> build, java.util.Map<String, String> env)
}
}

/* Check all repository URLs are not empty */
/* JENKINS-38608 reports an unhelpful error message when a repository URL is empty */
/* Throws an IllegalArgumentException because that exception is thrown by env.put() on a null argument */
int repoCount = 1;
for (UserRemoteConfig config:userRemoteConfigs) {
if (config.getUrl() == null) {
throw new IllegalArgumentException("Git repository URL " + repoCount + " is an empty string in job definition. Checkout requires a valid repository URL");
}
repoCount++;
}

if (userRemoteConfigs.size()==1){
env.put("GIT_URL", userRemoteConfigs.get(0).getUrl());
Expand Down Expand Up @@ -1689,11 +1716,13 @@ public void populateEnvironmentVariables(Map<String,String> env) {

private static final long serialVersionUID = 1L;

@Whitelisted
public boolean isDoGenerateSubmoduleConfigurations() {
return this.doGenerateSubmoduleConfigurations;
}

@Exported
@Whitelisted
public List<BranchSpec> getBranches() {
return branches;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Set;

import static org.apache.commons.lang.StringUtils.isNotBlank;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;

/**
* This is a portion of {@link GitSCM} for the stuff that's used to be in {@link GitSCM}
Expand Down Expand Up @@ -178,6 +179,7 @@ public abstract class GitSCMBackwardCompatibility extends SCM implements Seriali
private transient BuildChooser buildChooser;


@Whitelisted
abstract DescribableList<GitSCMExtension, GitSCMExtensionDescriptor> getExtensions();

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/hudson/plugins/git/SubmoduleConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Joiner;
import org.apache.commons.collections.CollectionUtils;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.DataBoundConstructor;

import java.util.Arrays;
Expand Down Expand Up @@ -31,6 +32,7 @@ public SubmoduleConfig(String submoduleName, Collection<String> branches) {
}
}

@Whitelisted
public String getSubmoduleName() {
return submoduleName;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/hudson/plugins/git/UserMergeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.jenkinsci.plugins.structs.describable.CustomDescribableModel;
import org.kohsuke.stapler.DataBoundSetter;

Expand Down Expand Up @@ -70,6 +71,7 @@ public UserMergeOptions(PreBuildMergeOptions pbm) {
* Repository name, such as 'origin' that designates which repository the branch lives in.
* @return repository name
*/
@Whitelisted
public String getMergeRemote() {
return mergeRemote;
}
Expand All @@ -84,6 +86,7 @@ public void setMergeRemote(String mergeRemote) {
* Normally a branch name like 'master'.
* @return branch name from which merge will be performed
*/
@Whitelisted
public String getMergeTarget() {
return mergeTarget;
}
Expand Down
Loading

0 comments on commit 1916bf9

Please sign in to comment.