Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-43052] Warn in Pipeline build log if a deprecated extension is used #1639

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@
*/
public abstract class GitSCMExtension extends AbstractDescribableImpl<GitSCMExtension> {

/**
* When extensions created for freestyle projects have a more
* general purpose replacement in Pipeline, the more general
* purpose Pipeline step is preferred. This method allows the
* deprecated extension to suggest the preferred alternative.
*
* If the extension should not be used in Pipeline and there is an
* alternative syntax that should be used, return the alternative
* syntax suggestion.
*
* If the extension should not be used in Pipeline and there is no
* alternative syntax suggestion, return an empty string.
*
* If the extension should be used in Pipeline, return null.
*
* @return alternative syntax suggestion for Pipeline syntax to replace this extension.
* Null indicates the extension is intended for use in Pipeline.
*/
@CheckForNull
public String getDeprecationAlternative() {
return null;
}

/**
* @return <code>true</code> when this extension has a requirement to get a workspace during polling,
* typically as it has to check for incoming changes, not just remote HEAD.
Expand Down Expand Up @@ -142,7 +165,7 @@
return rev;
}
}

@Deprecated
public Revision decorateRevisionToBuild(GitSCM scm, AbstractBuild<?,?> build, GitClient git, BuildListener listener, Revision marked, Revision rev) throws IOException, InterruptedException, GitException {
if (Util.isOverridden(GitSCMExtension.class, getClass(), "decorateRevisionToBuild", GitSCM.class, Run.class, GitClient.class, TaskListener.class, Revision.class, Revision.class)) {
Expand All @@ -166,6 +189,15 @@
if (build instanceof AbstractBuild && listener instanceof BuildListener) {
beforeCheckout(scm, (AbstractBuild) build, git, (BuildListener) listener);
}
String message = "***DEPRECATED*** " + getDescriptor().getDisplayName() + " is deprecated in Pipeline.";
String alternative = getDeprecationAlternative();
if (alternative != null && !(build instanceof AbstractBuild)) {
if (alternative.isEmpty()) {

Check warning on line 195 in src/main/java/hudson/plugins/git/extensions/GitSCMExtension.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 195 is only partially covered, one branch is missing
listener.getLogger().println(message);

Check warning on line 196 in src/main/java/hudson/plugins/git/extensions/GitSCMExtension.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 196 is not covered by tests
} else {
listener.getLogger().println(message + " " + getDeprecationAlternative());
}
}
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.git.extensions.impl;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.Extension;
import hudson.model.Item;
import hudson.plugins.git.extensions.FakeGitSCMExtension;
Expand Down Expand Up @@ -30,6 +31,13 @@ public BuildChooser getBuildChooser() {
return buildChooser;
}

@Override
@CheckForNull
public String getDeprecationAlternative() {
// This extension is not intended to be used in Pipeline
return "Use separate Pipeline jobs for individual branches instead of switching between branches with the same job.";
}

@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.git.extensions.impl;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.Extension;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
Expand All @@ -21,6 +22,13 @@ public boolean requiresWorkspaceForPolling() {
return true;
}

@Override
@CheckForNull
public String getDeprecationAlternative() {
// This extension is not intended to be used in Pipeline
return "Use poll: false instead.";
}

@Extension
// No @Symbol annotation, because force polling using workspace should not be used in Pipeline
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.git.extensions.impl;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.Extension;
import hudson.plugins.git.extensions.FakeGitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
Expand All @@ -15,6 +16,14 @@
public IgnoreNotifyCommit() {
}

@Override
@CheckForNull
public String getDeprecationAlternative() {
// This extension is not intended to be used in Pipeline
// No alternative is offered because notifyCommits should be ignored at a higher level in Pipeline
return "";

Check warning on line 24 in src/main/java/hudson/plugins/git/extensions/impl/IgnoreNotifyCommit.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 24 is not covered by tests
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public class MessageExclusion extends GitSCMExtension {

public String getExcludedMessage() { return excludedMessage; }

@Override
@CheckForNull
public String getDeprecationAlternative() {
// This extension is not intended to be used in Pipeline
return "Use exclusion traits in multibranch Pipelines to exclude commit messages";
}

@Override
@SuppressFBWarnings(value="NP_BOOLEAN_RETURN_NULL", justification="null used to indicate other extensions should decide")
@CheckForNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public boolean requiresWorkspaceForPolling() {
return true;
}

@Override
@CheckForNull
public String getDeprecationAlternative() {
// This extension is not intended to be used in Pipeline
return "Use exclusion traits in multibranch Pipelines to exclude commit paths.";
}

@DataBoundConstructor
public PathRestriction(String includedRegions, String excludedRegions) {
this.includedRegions = includedRegions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.git.extensions.impl;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.AbortException;
import hudson.Extension;
import hudson.plugins.git.GitException;
Expand Down Expand Up @@ -137,6 +138,13 @@ public GitClientType getRequiredClient() {
return GitClientType.GITCLI;
}

@Override
@CheckForNull
public String getDeprecationAlternative() {
// This extension is not intended to be used in Pipeline
return "Use shell or bat or powershell steps to implement git merge.";
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package hudson.plugins.git.extensions.impl;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.model.AbstractBuild;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.git.GitException;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.Messages;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
Expand All @@ -33,6 +37,13 @@ public String getRelativeTargetDir() {
return relativeTargetDir;
}

@Override
@CheckForNull
public String getDeprecationAlternative() {
// This extension is not intended to be used in Pipeline
return "Use 'dir()' or 'ws()' to checkout into a different Pipeline workspace directory.";
}

@Override
public FilePath getWorkingDirectory(GitSCM scm, Job<?, ?> context, FilePath workspace, EnvVars environment, TaskListener listener) throws IOException, InterruptedException, GitException {
if (relativeTargetDir == null || relativeTargetDir.length() == 0 || relativeTargetDir.equals(".")) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/hudson/plugins/git/extensions/impl/ScmName.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.git.extensions.impl;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.Extension;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.FakeGitSCMExtension;
Expand All @@ -19,6 +20,16 @@
this.name = name;
}

@Override
@CheckForNull
public String getDeprecationAlternative() {
// This extension is not intended to be used in Pipeline
// Custom SCM name should be set directly by Pipeline
// arguments when performing multiple checkouts in a single
// Pipeline.
return "Use the custom scm name as the userRemoteConfigs value for 'name'";

Check warning on line 30 in src/main/java/hudson/plugins/git/extensions/impl/ScmName.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 30 is not covered by tests
}

public String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.git.extensions.impl;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.Extension;
import hudson.model.Run;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -30,6 +31,13 @@
git.getWorkTree().deleteContents();
}

@Override
@CheckForNull
public String getDeprecationAlternative() {
// This extension is not intended to be used in Pipeline
return "Use cleanWs() to empty the Pipeline workspace before checkout.";

Check warning on line 38 in src/main/java/hudson/plugins/git/extensions/impl/WipeWorkspace.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 38 is not covered by tests
}

/**
* {@inheritDoc}
*/
Expand Down