Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #198 from jglick/multibranch-globalVariable
Browse files Browse the repository at this point in the history
[JENKINS-30222] Multibranch/global var incompatibility
  • Loading branch information
jglick committed Aug 31, 2015
2 parents c1699b7 + ec14e87 commit 2394bf9
Showing 1 changed file with 42 additions and 0 deletions.
Expand Up @@ -24,16 +24,21 @@

package org.jenkinsci.plugins.workflow.multibranch;

import hudson.ExtensionList;
import hudson.model.RootAction;
import hudson.plugins.mercurial.MercurialInstallation;
import hudson.plugins.mercurial.MercurialSCMSource;
import hudson.tools.ToolProperty;
import java.io.File;
import java.util.Collections;
import jenkins.branch.BranchProperty;
import jenkins.branch.BranchSource;
import jenkins.branch.DefaultBranchPropertyStrategy;
import jenkins.plugins.git.GitSCMSource;
import jenkins.scm.impl.subversion.SubversionSCMSource;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.workflow.cps.global.WorkflowLibRepository;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.steps.scm.GitSampleRepoRule;
Expand Down Expand Up @@ -187,4 +192,41 @@ public class SCMBinderTest {
});
}

@Test public void globalVariable() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
// Set up a standardJob definition:
WorkflowLibRepository repo = ExtensionList.lookup(RootAction.class).get(WorkflowLibRepository.class);
File vars = new File(repo.workspace, /*UserDefinedGlobalVariable.PREFIX*/ "vars");
vars.mkdirs();
// TODO is this safe to add to generic-whitelist? (Why are global libs even being run through the sandbox to begin with?)
ScriptApproval.get().approveSignature("method groovy.lang.Closure getOwner");
FileUtils.writeStringToFile(new File(vars, "standardJob.groovy"),
"def call(body) {\n" +
" def config = [:]\n" +
" body.resolveStrategy = Closure.DELEGATE_FIRST\n" +
" body.delegate = config\n" +
" body()\n" +
" node {\n" +
" checkout body.owner.scm\n" +
" echo \"loaded ${readFile config.file}\"\n" +
" }\n" +
"}\n");
// Then a project using it:
sampleGitRepo.init();
sampleGitRepo.write("Jenkinsfile", "standardJob {file = 'resource'}");
sampleGitRepo.write("resource", "resource content");
sampleGitRepo.git("add", "Jenkinsfile");
sampleGitRepo.git("add", "resource");
sampleGitRepo.git("commit", "--all", "--message=flow");
// And run:
WorkflowMultiBranchProject mp = story.j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
WorkflowJob p = WorkflowMultiBranchProjectTest.findBranchProject(mp, "master");
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("loaded resource content", b);
}
});
}

}

0 comments on commit 2394bf9

Please sign in to comment.