use of jenkins.plugins.git.GitStep in project workflow-cps-plugin by jenkinsci.
the class CpsScmFlowDefinitionTest method emptyChangeLogEmptyChangeSets.
@Issue("JENKINS-29881")
@Test
public void emptyChangeLogEmptyChangeSets() throws Exception {
sampleRepo.init();
sampleRepo.write("flow.groovy", "echo 'version one'");
sampleRepo.git("add", "flow.groovy");
sampleRepo.git("commit", "--message=init");
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
CpsScmFlowDefinition def = new CpsScmFlowDefinition(new GitStep(sampleRepo.toString()).createSCM(), "flow.groovy");
def.setLightweight(false);
p.setDefinition(def);
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("Cloning the remote Git repository", b);
r.assertLogContains("version one", b);
r.assertLogNotContains("Retrying after 10 seconds", b);
b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(2, b.number);
List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b.getChangeSets();
assertEquals(Collections.emptyList(), changeSets);
}
use of jenkins.plugins.git.GitStep in project workflow-cps-plugin by jenkinsci.
the class CpsScmFlowDefinitionTest method configRoundtrip.
@Test
public void configRoundtrip() throws Exception {
sampleRepo.init();
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
CpsScmFlowDefinition def = new CpsScmFlowDefinition(new GitStep(sampleRepo.toString()).createSCM(), "Jenkinsfile");
def.setLightweight(true);
p.setDefinition(def);
r.configRoundtrip(p);
def = (CpsScmFlowDefinition) p.getDefinition();
assertEquals("Jenkinsfile", def.getScriptPath());
assertTrue(def.isLightweight());
assertEquals(GitSCM.class, def.getScm().getClass());
}
use of jenkins.plugins.git.GitStep in project workflow-cps-plugin by jenkinsci.
the class CpsScmFlowDefinitionTest method scriptPathSymlinksCannotEscapeCheckoutDirectory.
@Issue("SECURITY-2595")
@Test
public void scriptPathSymlinksCannotEscapeCheckoutDirectory() throws Exception {
// On Windows, the symlink is treated as a regular file, so there is no vulnerability, but the error message is different.
assumeFalse(Functions.isWindows());
sampleRepo.init();
Path secrets = Paths.get(sampleRepo.getRoot().getPath(), "Jenkinsfile");
Files.createSymbolicLink(secrets, Paths.get(r.jenkins.getRootDir() + "/secrets/master.key"));
sampleRepo.git("add", ".");
sampleRepo.git("commit", "-m", "init");
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
GitStep step = new GitStep(sampleRepo.toString());
p.setDefinition(new CpsScmFlowDefinition(step.createSCM(), "Jenkinsfile"));
WorkflowRun b = r.buildAndAssertStatus(Result.FAILURE, p);
assertThat(b.getExecution(), nullValue());
r.assertLogContains("Jenkinsfile references a file that is not inside " + r.jenkins.getWorkspaceFor(p), b);
}
use of jenkins.plugins.git.GitStep in project workflow-cps-plugin by jenkinsci.
the class CpsScmFlowDefinitionTest method retry.
@Issue("JENKINS-39194")
@Test
public void retry() throws Exception {
// We use an un-initialized repo here to test retry
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
GitStep step = new GitStep(invalidRepo.toString());
CpsScmFlowDefinition def = new CpsScmFlowDefinition(step.createSCM(), "flow.groovy");
def.setLightweight(false);
p.setDefinition(def);
r.jenkins.setScmCheckoutRetryCount(1);
WorkflowRun b = r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0));
r.assertLogContains("Could not read from remote repository", b);
r.assertLogContains("Retrying after 10 seconds", b);
}
use of jenkins.plugins.git.GitStep in project workflow-cps-plugin by jenkinsci.
the class CpsScmFlowDefinitionTest method checkoutDirectoriesAreNotReusedByDifferentScms.
@Issue("SECURITY-2463")
@Test
public void checkoutDirectoriesAreNotReusedByDifferentScms() throws Exception {
// Checkout hook is not cross-platform.
assumeFalse(Functions.isWindows());
sampleRepo.init();
sampleRepo.write("Jenkinsfile", "echo('git library')");
sampleRepo.git("add", "Jenkinsfile");
sampleRepo.git("commit", "--message=init");
sampleRepoSvn.init();
sampleRepoSvn.write("Jenkinsfile", "echo('subversion library')");
// Copy .git folder from the Git repo into the SVN repo as data.
File gitDirInSvnRepo = new File(sampleRepoSvn.wc(), ".git");
FileUtils.copyDirectory(new File(sampleRepo.getRoot(), ".git"), gitDirInSvnRepo);
String jenkinsRootDir = r.jenkins.getRootDir().toString();
// Add a Git post-checkout hook to the .git folder in the SVN repo.
Path postCheckoutHook = gitDirInSvnRepo.toPath().resolve("hooks/post-checkout");
// Always create hooks directory for compatibility with https://github.com/jenkinsci/git-plugin/pull/1207.
Files.createDirectories(postCheckoutHook.getParent());
Files.write(postCheckoutHook, ("#!/bin/sh\ntouch '" + jenkinsRootDir + "/hook-executed'\n").getBytes(StandardCharsets.UTF_8));
sampleRepoSvn.svnkit("add", sampleRepoSvn.wc() + "/Jenkinsfile");
sampleRepoSvn.svnkit("add", sampleRepoSvn.wc() + "/.git");
sampleRepoSvn.svnkit("propset", "svn:executable", "ON", sampleRepoSvn.wc() + "/.git/hooks/post-checkout");
sampleRepoSvn.svnkit("commit", "--message=init", sampleRepoSvn.wc());
// Run a build using the SVN repo.
WorkflowJob p = r.createProject(WorkflowJob.class);
p.setDefinition(new CpsScmFlowDefinition(new SubversionSCM(sampleRepoSvn.trunkUrl()), "Jenkinsfile"));
r.buildAndAssertSuccess(p);
// Run a build using the Git repo. It should be checked out to a different directory than the SVN repo.
p.setDefinition(new CpsScmFlowDefinition(new GitStep(sampleRepo.toString()).createSCM(), "Jenkinsfile"));
WorkflowRun b2 = r.buildAndAssertSuccess(p);
assertThat(new File(r.jenkins.getRootDir(), "hook-executed"), not(anExistingFile()));
}
Aggregations