use of org.jenkinsci.test.acceptance.junit.WithDocker in project acceptance-test-harness by jenkinsci.
the class WarningsPluginTest method should_parse_codenarc_on_agent.
@Test
@Issue("JENKINS-17787")
@WithPlugins({ "violations", "ssh-slaves" })
@WithDocker
@Ignore("Reproduces JENKINS-17787")
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = { CREDENTIALS_ID, CREDENTIALS_KEY })
public void should_parse_codenarc_on_agent() {
DumbSlave dockerSlave = createDockerAgent();
FreeStyleJob job = prepareDockerSlave(dockerSlave);
assertThatCodeNarcActionExists(job);
}
use of org.jenkinsci.test.acceptance.junit.WithDocker in project acceptance-test-harness by jenkinsci.
the class WarningsPluginTest method should_scan_console_log_of_slave_build.
@Test
@WithDocker
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = { CREDENTIALS_ID, CREDENTIALS_KEY })
@WithPlugins("ssh-slaves")
public void should_scan_console_log_of_slave_build() throws ExecutionException, InterruptedException {
DumbSlave dockerSlave = createDockerAgent();
FreeStyleJob job = prepareDockerSlave(dockerSlave);
job.configure();
job.copyResource(resource(RESOURCE_WARNING_MAIN_JAVA_PATH));
ShellBuildStep shellBuildStep = job.addBuildStep(ShellBuildStep.class);
shellBuildStep.command(CMD_WARNING_MAIN_JAVA_CONSOLE);
WarningsPublisher warningsPublisher = job.addPublisher(WarningsPublisher.class);
warningsPublisher.addConsoleScanner(JAVA_ID);
job.save();
Build build = job.startBuild().shouldSucceed();
assertThatActionExists(job, build, "Java Warnings");
WarningsAction action = createJavaResultAction(build);
assertThatWarningsCountInSummaryIs(action, 3);
String codeLine = action.getLinkedSourceFileText(AnalysisAction.Tab.DETAILS, "WarningMain.java", 10);
String[] codeLineArr = codeLine.trim().split("\\s+", 2);
assertThat("Warning should be at line", codeLineArr[0], is("10"));
assertThat("Assert failed comparing code line is", codeLineArr[1], is("text = (TextClass) text2;"));
}
use of org.jenkinsci.test.acceptance.junit.WithDocker in project acceptance-test-harness by jenkinsci.
the class WorkflowPluginTest method subversion.
/**
* Pipeline analogue of {@link SubversionPluginTest#build_has_changes}.
*/
@Category(DockerTest.class)
@WithDocker
@WithPlugins({ "workflow-cps@2.12", "workflow-job@2.5", "workflow-durable-task-step@2.4", "subversion@2.6" })
@Test
public void subversion() throws Exception {
final SvnContainer svnContainer = svn.get();
WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
job.script.set("node {svn '" + svnContainer.getUrlUnauthenticatedRepoAtRevision(1) + "'}");
job.save();
job.startBuild().shouldSucceed();
job.configure();
job.script.set("node {svn '" + svnContainer.getUrlUnauthenticatedRepoAtRevision(2) + "'}");
job.save();
Build b2 = job.startBuild().shouldSucceed();
assertTrue(b2.getChanges().hasChanges());
}
use of org.jenkinsci.test.acceptance.junit.WithDocker 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"));
}
use of org.jenkinsci.test.acceptance.junit.WithDocker 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"));
}
}
Aggregations