Skip to content
Permalink
Browse files

JENKINS-47214 globally disable autofavorite using system property (#13)

-DBLUEOCEAN_FEATURE_AUTOFAVORITE_ENABLED=false
  • Loading branch information
i386 committed Nov 29, 2017
1 parent 95ee516 commit 80930fe881c6b738a452e3f018c81b53b18f0fb6
@@ -23,6 +23,7 @@
import hudson.util.LogTaskListener;
import io.jenkins.blueocean.autofavorite.user.FavoritingUserProperty;
import jenkins.branch.MultiBranchProject;
import jenkins.util.SystemProperties;
import org.apache.commons.io.IOUtils;
import org.eclipse.jgit.errors.MissingObjectException;
import org.jenkinsci.plugins.gitclient.Git;
@@ -46,6 +47,11 @@

@Override
public void onCheckout(Run<?, ?> build, SCM scm, FilePath workspace, TaskListener listener, @CheckForNull File changelogFile, @CheckForNull SCMRevisionState pollingBaseline) throws Exception {

if (!isEnabled()) {
return;
}

// Look for the first build of a multibranch job
if (!(build instanceof WorkflowRun
&& ((WorkflowRun) build).getParent().getParent() instanceof MultiBranchProject
@@ -157,4 +163,10 @@ private GitChangeSet getChangeSet(GitSCM scm, FilePath workspace, Revision lastB
}
return Iterables.getOnlyElement(changeSets, null);
}

static boolean isEnabled() {
return SystemProperties.getBoolean(BLUEOCEAN_FEATURE_AUTOFAVORITE_ENABLED_PROPERTY, true);
}

static final String BLUEOCEAN_FEATURE_AUTOFAVORITE_ENABLED_PROPERTY = "BLUEOCEAN_FEATURE_AUTOFAVORITE_ENABLED";
}
@@ -13,6 +13,7 @@
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
@@ -46,6 +47,27 @@ public void testAutoFavoriteForRegisteredUserWhenDisabled() throws Exception {
assertFalse(Favorites.isFavorite(user, job));
}

@Test
public void testAutoFavoriteForRegisteredUserWhenGloballyDisabled() throws Exception {
User jdumay = User.getById("jdumay", true);
assertNotNull(jdumay);

// Disable autofavorite
assertTrue(FavoritingScmListener.isEnabled());
System.setProperty(FavoritingScmListener.BLUEOCEAN_FEATURE_AUTOFAVORITE_ENABLED_PROPERTY, "false");
assertFalse(FavoritingScmListener.isEnabled());

WorkflowJob job = createAndRunPipeline();
User user = User.getById("jdumay", false);
assertNotNull(user);
assertFalse(Favorites.isFavorite(user, job));
}

@After
public void enableFeature() {
System.setProperty(FavoritingScmListener.BLUEOCEAN_FEATURE_AUTOFAVORITE_ENABLED_PROPERTY, "true");
}

// @Test
/** Disabled because of https://issues.jenkins-ci.org/browse/JENKINS-39694 **/
public void testAutoFavoriteForNonRegisteredUser() throws Exception {

0 comments on commit 80930fe

Please sign in to comment.
You can’t perform that action at this time.