Search in sources :

Example 11 with WithCredentials

use of org.jenkinsci.test.acceptance.junit.WithCredentials in project acceptance-test-harness by jenkinsci.

the class SubversionPluginTest method run_basic_subversion_build_userPwd.

@Test
@WithCredentials(credentialType = WithCredentials.USERNAME_PASSWORD, values = { SvnContainer.USER, SvnContainer.PWD }, id = SvnContainer.USER)
public void run_basic_subversion_build_userPwd() throws SubversionPluginTestException {
    final SvnContainer svnContainer = svn.get();
    final FreeStyleJob f = jenkins.jobs.create();
    f.addShellStep("test -d .svn");
    final SubversionScm subversionScm = f.useScm(SubversionScm.class);
    subversionScm.url.set(svnContainer.getUrlAuthenticatedRepo());
    subversionScm.credentials.select(SvnContainer.USER);
    f.save();
    Build b = f.startBuild().shouldSucceed();
    assertThat(b.getConsole(), Matchers.containsString("test -d .svn"));
}
Also used : SvnContainer(org.jenkinsci.test.acceptance.docker.fixtures.SvnContainer) SubversionScm(org.jenkinsci.test.acceptance.plugins.subversion.SubversionScm) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) WithCredentials(org.jenkinsci.test.acceptance.junit.WithCredentials) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) DockerTest(org.jenkinsci.test.acceptance.junit.DockerTest)

Example 12 with WithCredentials

use of org.jenkinsci.test.acceptance.junit.WithCredentials in project acceptance-test-harness by jenkinsci.

the class WorkflowPluginTest method hello_world_from_git.

@Category(DockerTest.class)
@WithDocker
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = { CREDENTIALS_ID, KEY_FILENAME })
@WithPlugins({ "workflow-job", "workflow-cps", "workflow-basic-steps", "git" })
@Test
public void hello_world_from_git() throws IOException {
    String gitRepositoryUrl = createGitRepositoryInDockerContainer();
    WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
    job.setJenkinsFileRepository(gitRepositoryUrl, CREDENTIALS_ID);
    job.save();
    Build build = job.startBuild().shouldSucceed();
    assertThat(build.getConsole(), containsString("Hello Jenkinsfile in Git"));
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) Matchers.containsString(org.hamcrest.Matchers.containsString) WorkflowJob(org.jenkinsci.test.acceptance.po.WorkflowJob) Category(org.junit.experimental.categories.Category) WithCredentials(org.jenkinsci.test.acceptance.junit.WithCredentials) 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 13 with WithCredentials

use of org.jenkinsci.test.acceptance.junit.WithCredentials 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 14 with WithCredentials

use of org.jenkinsci.test.acceptance.junit.WithCredentials in project acceptance-test-harness by jenkinsci.

the class SubversionPluginTest method run_basic_subversion_build_svn_userPwd.

@Test
@WithCredentials(credentialType = WithCredentials.USERNAME_PASSWORD, values = { SvnContainer.USER, SvnContainer.PWD }, id = SvnContainer.USER)
public void run_basic_subversion_build_svn_userPwd() throws SubversionPluginTestException {
    final SvnContainer svnContainer = svn.get();
    final FreeStyleJob f = jenkins.jobs.create();
    f.addShellStep("test -d .svn");
    final SubversionScm subversionScm = f.useScm(SubversionScm.class);
    subversionScm.url.set(svnContainer.getSvnUrl());
    subversionScm.credentials.select(SvnContainer.USER);
    f.save();
    Build b = f.startBuild().shouldSucceed();
    assertThat(b.getConsole(), Matchers.containsString("test -d .svn"));
}
Also used : SvnContainer(org.jenkinsci.test.acceptance.docker.fixtures.SvnContainer) SubversionScm(org.jenkinsci.test.acceptance.plugins.subversion.SubversionScm) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) WithCredentials(org.jenkinsci.test.acceptance.junit.WithCredentials) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) DockerTest(org.jenkinsci.test.acceptance.junit.DockerTest)

Example 15 with WithCredentials

use of org.jenkinsci.test.acceptance.junit.WithCredentials in project acceptance-test-harness by jenkinsci.

the class OpenstackCloudPluginTest method usePerBuildInstance.

@Test
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = { MACHINE_USERNAME, "/openstack_plugin/unsafe" })
@TestActivation({ "HARDWARE_ID", "IMAGE_ID", "KEY_PAIR_NAME", "NETWORK_ID" })
public void usePerBuildInstance() {
    configureCloudInit("cloud-init");
    configureProvisioning("SSH", "unused");
    FreeStyleJob job = jenkins.jobs.create();
    job.configure();
    OpenstackBuildWrapper bw = job.addBuildWrapper(OpenstackBuildWrapper.class);
    bw.cloud(CLOUD_NAME);
    bw.template(CLOUD_DEFAULT_TEMPLATE);
    bw.count(1);
    // Wait a little for the other machine to start responding
    job.addShellStep("while ! ping -c 1 \"$JCLOUDS_IPS\"; do :; done");
    job.save();
    job.scheduleBuild().waitUntilFinished(PROVISIONING_TIMEOUT).shouldSucceed();
}
Also used : OpenstackBuildWrapper(org.jenkinsci.test.acceptance.plugins.openstack.OpenstackBuildWrapper) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) WithCredentials(org.jenkinsci.test.acceptance.junit.WithCredentials) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) TestActivation(org.jenkinsci.test.acceptance.junit.TestActivation)

Aggregations

WithCredentials (org.jenkinsci.test.acceptance.junit.WithCredentials)21 Test (org.junit.Test)21 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)14 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)13 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)11 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)10 TestActivation (org.jenkinsci.test.acceptance.junit.TestActivation)8 Build (org.jenkinsci.test.acceptance.po.Build)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)5 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)5 Issue (org.jvnet.hudson.test.Issue)5 WarningsAction (org.jenkinsci.test.acceptance.plugins.warnings.WarningsAction)3 WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 SvnContainer (org.jenkinsci.test.acceptance.docker.fixtures.SvnContainer)2 SubversionScm (org.jenkinsci.test.acceptance.plugins.subversion.SubversionScm)2 WarningsPublisher (org.jenkinsci.test.acceptance.plugins.warnings.WarningsPublisher)2 MatrixBuild (org.jenkinsci.test.acceptance.po.MatrixBuild)2 Node (org.jenkinsci.test.acceptance.po.Node)2