Search in sources :

Example 6 with GitRepo

use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.

the class GitPluginTest method checkout_branch.

@Test
public void checkout_branch() {
    GitRepo repo = buildGitRepo();
    repo.git("branch", "svn");
    repo.transferToDockerContainer(host, port);
    job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME).branch("svn");
    job.addShellStep("test `git rev-parse origin/svn` = `git rev-parse HEAD`");
    job.save();
    job.startBuild().shouldSucceed();
}
Also used : GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo) GitScm(org.jenkinsci.test.acceptance.plugins.git.GitScm) Test(org.junit.Test)

Example 7 with GitRepo

use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.

the class GitPluginTest method custom_name_and_email.

@Test
public void custom_name_and_email() {
    final String USER_NAME = "fake";
    final String EMAIL = "fake@mail.net";
    GitRepo repo = buildGitRepo();
    repo.transferToDockerContainer(host, port);
    job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME).customNameAndMail(USER_NAME, EMAIL);
    job.addShellStep("touch test.txt &&\n" + "git add test.txt &&\n" + "git commit -m \"Next commit\" &&\n" + "git show");
    job.save();
    Build b = job.startBuild();
    b.shouldSucceed();
    String console = b.getConsole();
    assertThat(console, Matchers.containsRegexp(USER_NAME, Pattern.MULTILINE));
    assertThat(console, Matchers.containsRegexp(EMAIL, Pattern.MULTILINE));
}
Also used : GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo) Build(org.jenkinsci.test.acceptance.po.Build) GitScm(org.jenkinsci.test.acceptance.plugins.git.GitScm) Test(org.junit.Test)

Example 8 with GitRepo

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"));
    }
}
Also used : SshSlaveLauncher(org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher) GitContainer(org.jenkinsci.test.acceptance.docker.fixtures.GitContainer) GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo) DockerAgentContainer(org.jenkinsci.test.acceptance.docker.fixtures.DockerAgentContainer) Matchers.containsString(org.hamcrest.Matchers.containsString) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) CommandBuilder(org.jenkinsci.utils.process.CommandBuilder) WorkflowJob(org.jenkinsci.test.acceptance.po.WorkflowJob) Category(org.junit.experimental.categories.Category) WithCredentials(org.jenkinsci.test.acceptance.junit.WithCredentials) Issue(org.jvnet.hudson.test.Issue) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) DockerTest(org.jenkinsci.test.acceptance.junit.DockerTest) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins) WithDocker(org.jenkinsci.test.acceptance.junit.WithDocker)

Example 9 with GitRepo

use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.

the class GitPluginTest method inverse_strategy_to_choose_build.

@Test
public void inverse_strategy_to_choose_build() {
    final String BRANCH_NAME = "secondBranch";
    GitRepo repo = buildGitRepo();
    repo.createBranch(BRANCH_NAME);
    repo.transferToDockerContainer(host, port);
    job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME).chooseBuildStrategy("Inverse");
    job.save();
    Build b = job.startBuild();
    b.shouldSucceed();
    assertThat(b.getConsole(), Matchers.containsRegexp("Checking out Revision .* \\(origin/" + BRANCH_NAME + "\\)", Pattern.MULTILINE));
}
Also used : GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo) Build(org.jenkinsci.test.acceptance.po.Build) GitScm(org.jenkinsci.test.acceptance.plugins.git.GitScm) Test(org.junit.Test)

Example 10 with GitRepo

use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.

the class GitPluginTest method merge_before_build_test.

@Test
public void merge_before_build_test() {
    final String TEST_COMMIT_MESSAGE = "Branch test";
    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);
    repo.transferToDockerContainer(host, port);
    job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME).mergeBeforeBuild().setTxtMergeRemote("origin").setTxtMergeTarget(BRANCH_NAME);
    job.save();
    b = job.startBuild();
    b.shouldSucceed();
    String console = b.getConsole();
    String revision = getRevisionFromConsole(console);
    assertThat(console, Matchers.containsRegexp("Merging Revision .* \\(refs/remotes/origin/master\\) to origin/" + BRANCH_NAME, Pattern.MULTILINE));
    assertThat(console, Matchers.containsRegexp("git merge --ff " + revision, Pattern.MULTILINE));
    assertThat(console, Matchers.containsRegexp("Checking out Revision .* \\(origin/master, origin/" + BRANCH_NAME + "\\)", Pattern.MULTILINE));
}
Also used : GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo) Build(org.jenkinsci.test.acceptance.po.Build) GitScm(org.jenkinsci.test.acceptance.plugins.git.GitScm) Test(org.junit.Test)

Aggregations

GitRepo (org.jenkinsci.test.acceptance.plugins.git.GitRepo)19 Test (org.junit.Test)14 Build (org.jenkinsci.test.acceptance.po.Build)12 GitScm (org.jenkinsci.test.acceptance.plugins.git.GitScm)11 GitContainer (org.jenkinsci.test.acceptance.docker.fixtures.GitContainer)4 URL (java.net.URL)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 DockerAgentContainer (org.jenkinsci.test.acceptance.docker.fixtures.DockerAgentContainer)1 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)1 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)1 WithCredentials (org.jenkinsci.test.acceptance.junit.WithCredentials)1 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)1 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)1 SshSlaveLauncher (org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher)1 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)1 WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)1 CommandBuilder (org.jenkinsci.utils.process.CommandBuilder)1 Category (org.junit.experimental.categories.Category)1 Issue (org.jvnet.hudson.test.Issue)1