use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.
the class CheckStylePluginTest method createGitRepositoryInDockerContainer.
private String createGitRepositoryInDockerContainer() {
GitRepo repo = new GitRepo();
String main = "src/main/java";
repo.mkdir(main);
repo.addFilesIn(CHECKSTYLE_PLUGIN_ROOT + SAMPLE_CHECKSTYLE_PROJECT + "/" + main, main);
repo.commit("Sources commit.");
String test = "src/test/java";
repo.mkdir(test);
repo.addFilesIn(CHECKSTYLE_PLUGIN_ROOT + SAMPLE_CHECKSTYLE_PROJECT + "/" + test, test);
repo.commit("Tests commit.");
repo.addFilesIn(CHECKSTYLE_PLUGIN_ROOT + SAMPLE_CHECKSTYLE_PROJECT);
repo.commit("POM commit.");
GitContainer container = getDockerContainer();
repo.transferToDockerContainer(container.host(), container.port());
return container.getRepoUrl();
}
use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.
the class WorkflowPluginTest method sshGitInsideDocker.
@Category(DockerTest.class)
@WithDocker
@WithPlugins({ "workflow-cps@2.0", "workflow-job@2.0", "workflow-durable-task-step@2.0", "docker-workflow@1.5", "git", "ssh-agent@1.10", "ssh-slaves@1.11" })
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = { "git", "/org/jenkinsci/test/acceptance/docker/fixtures/GitContainer/unsafe" }, id = "gitcreds")
@Issue("JENKINS-27152")
@Test
public void sshGitInsideDocker() throws Exception {
GitContainer gitContainer = gitServer.get();
try (GitRepo repo = new GitRepo()) {
repo.changeAndCommitFoo("Initial commit");
repo.transferToDockerContainer(gitContainer.host(), gitContainer.port());
DumbSlave slave = jenkins.slaves.create(DumbSlave.class);
slave.setExecutors(1);
// TODO perhaps should be a constant in SshdContainer
slave.remoteFS.set("/home/test");
SshSlaveLauncher launcher = slave.setLauncher(SshSlaveLauncher.class);
Process proc = new ProcessBuilder("stat", "-c", "%g", "/var/run/docker.sock").start();
String group = IOUtils.toString(proc.getInputStream()).trim();
Assume.assumeThat("docker.sock can be statted", proc.waitFor(), is(0));
try {
Integer.parseInt(group);
} catch (NumberFormatException x) {
Assume.assumeNoException("unexpected output from stat on docker.sock", x);
}
// Note that we need to link to the Git container both on the agent, for the benefit of JGit (TODO pending JENKINS-30600), and in the build container, for the benefit of git-pull:
DockerAgentContainer agentContainer = agent.starter().withOptions(new CommandBuilder("--volume=/var/run/docker.sock:/var/run/docker.sock", "--env=DOCKER_GROUP=" + group, "--link=" + gitContainer.getCid() + ":git")).start();
launcher.host.set(agentContainer.ipBound(22));
launcher.port(agentContainer.port(22));
launcher.pwdCredentials("test", "test");
launcher.setSshHostKeyVerificationStrategy(SshSlaveLauncher.NonVerifyingKeyVerificationStrategy.class);
slave.save();
{
// TODO JENKINS-30600 workaround
JGitInstallation.addJGit(jenkins);
find(by.button("Save")).click();
}
WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
String networkOptions = StringUtils.isNotBlank(System.getenv("DOCKER_FIXTURES_NETWORK")) ? " --network=" + System.getenv("DOCKER_FIXTURES_NETWORK") : "";
String options = "--link=" + gitContainer.getCid() + ":git" + networkOptions;
String repoUrl = StringUtils.isNotBlank(System.getenv("DOCKER_FIXTURES_NETWORK")) ? gitContainer.getRepoUrlInsideDocker() : gitContainer.getRepoUrlInsideDocker("git");
job.script.set("node('" + slave.getName() + "') {\n" + " docker.image('cloudbees/java-build-tools').inside('" + options + "') {\n" + // TODO JENKINS-30600: " git url: '" + gitContainer.getRepoUrlInsideDocker("git") + "', credentialsId: 'gitcreds'\n" +
" checkout([$class: 'GitSCM', userRemoteConfigs: [[url: '" + repoUrl + "', credentialsId: 'gitcreds']], gitTool: 'jgit'])\n" + " sh 'mkdir ~/.ssh && echo StrictHostKeyChecking no > ~/.ssh/config'\n" + " sshagent(['gitcreds']) {sh 'ls -l $SSH_AUTH_SOCK && git pull origin master'}\n" + " }\n" + "}");
job.sandbox.check();
job.save();
assertThat(job.startBuild().shouldSucceed().getConsole(), containsString("-> FETCH_HEAD"));
}
}
use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.
the class GitPluginTest method calculate_changelog.
@Test
public void calculate_changelog() {
final URL changesUrl;
final String TEST_COMMIT_MESSAGE = "Second commit";
Build b;
GitRepo repo = buildGitRepo();
repo.createBranch("testBranch");
repo.changeAndCommitFoo(TEST_COMMIT_MESSAGE);
repo.transferToDockerContainer(host, port);
job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME).calculateChangelog("origin", "testBranch");
job.save();
b = job.startBuild();
b.shouldSucceed();
changesUrl = b.url("changes");
assertThat(b.getConsole(), Matchers.containsRegexp("Using 'Changelog to branch' strategy.", Pattern.MULTILINE));
assertThat(visit(changesUrl).getPageSource(), Matchers.containsRegexp(TEST_COMMIT_MESSAGE, Pattern.MULTILINE));
}
use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.
the class GitPluginTest method create_tag_for_build.
@Test
public void create_tag_for_build() {
GitRepo repo = buildGitRepo();
repo.transferToDockerContainer(host, port);
job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME).customNameAndMail("fake", "fake@mail.com").createTagForBuild();
job.addShellStep("git tag -n1");
job.save();
Build b = job.startBuild();
b.shouldSucceed();
assertThat(b.getConsole(), Matchers.containsRegexp("jenkins-" + job.name + "-1 Jenkins Build #1", Pattern.MULTILINE));
}
use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.
the class GitPluginTest method commit_author_in_changelog_test.
@Test
public void commit_author_in_changelog_test() {
URL changesUrl;
final String TEST_COMMIT_MESSAGE = "Second commit";
final String BRANCH_NAME = "testBranch";
final String TEST_FILE = "foo_test_branch";
Build b;
GitRepo repo = buildGitRepo();
repo.createBranch(BRANCH_NAME);
repo.touch(TEST_FILE);
repo.git("add", TEST_FILE);
repo.git("commit", "-m", TEST_COMMIT_MESSAGE, "--author", "New-Author <other-email@example.org>");
repo.transferToDockerContainer(host, port);
job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME).calculateChangelog("origin", BRANCH_NAME);
job.save();
b = job.startBuild();
b.shouldSucceed();
changesUrl = b.url("changes");
assertThat(visit(changesUrl).getPageSource(), Matchers.containsRegexp("/user/jenkins-ath/", Pattern.MULTILINE));
job.configure();
job.useScm(GitScm.class).commitAuthorInChangelog();
job.save();
b = job.startBuild();
b.shouldSucceed();
changesUrl = b.url("changes");
assertThat(visit(changesUrl).getPageSource(), Matchers.containsRegexp("/user/other-email/", Pattern.MULTILINE));
}
Aggregations