Java 类hudson.tasks.Shell 实例源码

项目:marathon-plugin    文件:MarathonRecorderTest.java   
/**
 * Test that when "marathon.json" is not present the build is failed
 * and no requests are made to the configured Marathon instance.
 *
 * @throws Exception
 */
@Test
public void testRecorderNoFile() throws Exception {
    final FreeStyleProject project = j.createFreeStyleProject();
    project.getBuildersList().add(new Shell("echo hello"));

    // add recorder
    project.getPublishersList().add(new MarathonRecorder(TestUtils.getHttpAddresss(httpServer)));

    // run a build with the shell step and recorder publisher
    final FreeStyleBuild build = j.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(0).get());
    // assert things
    j.assertLogContains("[Marathon]", build);
    j.assertLogContains("marathon.json", build);
    assertEquals("No web requests were made", 0, httpServer.getRequestCount());
}
项目:parameter-pool-plugin    文件:ParameterPoolTest.java   
@Test
public void pickFirstErrorBuildIfPreferringErrors() throws Exception {
    FreeStyleProject project = createProject(0, true);

    Shell exitShell = new Shell("exit 1");
    project.getBuildersList().add(exitShell);
    project.scheduleBuild2(0).waitForStart().run();
    project.scheduleBuild2(0).waitForStart().run();

    project.getBuildersList().remove(exitShell);

    FreeStyleBuild successfulBuildAfterFailures = project.scheduleBuild2(0).get();
    String logText = FileUtils.readFileToString(successfulBuildAfterFailures.getLogFile());
    assertEquals(logText, Result.SUCCESS, successfulBuildAfterFailures.getResult());

    FreeStyleBuild completedBuild = project.scheduleBuild2(0).get();
    logText = FileUtils.readFileToString(completedBuild.getLogFile());
    assertThatVmIsInText(completedBuild.getNumber(), 2, logText);
}
项目:sumologic-jenkins-plugin    文件:SumoBuildNotifierTest.java   
@Test
public void testSendBuildData() throws Exception {
  ArgumentCaptor<HttpRequest> captor = ArgumentCaptor.forClass(HttpRequest.class);
  FreeStyleProject project = j.createFreeStyleProject();

  project.getBuildersList().add(new Shell("Echo Hello"));
  project.getBuildersList().add(new Shell("Echo Hello2"));
  project.getBuildersList().add(new Shell("Echo Hello3"));
  project.getBuildersList().add(new Shell("Echo Hello4"));
  project.getPublishersList().add(new SumoBuildNotifier());

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  Mockito.verify(handler, atLeast(1)).handle(
      captor.capture(),
      Mockito.isA(HttpResponse.class),
      Mockito.isA(HttpContext.class));

  HttpEntityEnclosingRequest request = (HttpEntityEnclosingRequest) captor.getValue();


  Assert.assertTrue("Message too short.", ModelFactory.createBuildModel(build).toJson().length() <= request.getEntity().getContentLength());
}
项目:yet-another-docker-plugin    文件:FreestyleTest.java   
@Override
public Boolean call() throws Throwable {
    final Jenkins jenkins = Jenkins.getInstance();

    // prepare job
    final FreeStyleProject project = jenkins.createProject(FreeStyleProject.class, "freestyle-project");
    final Shell env = new Shell("env");
    project.getBuildersList().add(env);
    project.setAssignedLabel(new LabelAtom(DOCKER_CLOUD_LABEL));
    project.save();

    LOG.trace("trace test.");
    project.scheduleBuild(new TestCause());

    // image pull may take time
    waitUntilNoActivityUpTo(jenkins, 10 * 60 * 1000);

    final FreeStyleBuild lastBuild = project.getLastBuild();
    assertThat(lastBuild, not(nullValue()));
    assertThat(lastBuild.getResult(), is(Result.SUCCESS));

    assertThat(getLog(lastBuild), Matchers.containsString(TEST_VALUE));
    assertThat(getLog(lastBuild), Matchers.containsString(CLOUD_ID + "=" + DOCKER_CLOUD_NAME));

    return true;
}
项目:yet-another-docker-plugin    文件:DockerSimpleBuildWrapperTest.java   
@Ignore("For local experiments")
@Test
public void testWrapper() throws Exception {
    final FreeStyleProject project = jRule.createProject(FreeStyleProject.class, "freestyle");

    final DockerConnector connector = new DockerConnector("tcp://" + ADDRESS + ":2376/");
    connector.setConnectorType(JERSEY);

    final DockerSlaveConfig config = new DockerSlaveConfig();
    config.getDockerContainerLifecycle().setImage("java:8-jdk-alpine");
    config.setLauncher(new NoOpDelegatingComputerLauncher(new DockerComputerSingleJNLPLauncher()));
    config.setRetentionStrategy(new DockerOnceRetentionStrategy(10));

    final DockerSimpleBuildWrapper dockerSimpleBuildWrapper = new DockerSimpleBuildWrapper(connector, config);
    project.getBuildWrappersList().add(dockerSimpleBuildWrapper);
    project.getBuildersList().add(new Shell("sleep 30"));

    final QueueTaskFuture<FreeStyleBuild> taskFuture = project.scheduleBuild2(0);

    jRule.waitUntilNoActivity();
    jRule.pause();
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testFilePlainWithFailureAndUpload() throws Exception {
  forFailedJobs = true;

  underTest = new GoogleCloudStorageUploader(CREDENTIALS_ID,
      ImmutableList.<AbstractUpload>of(setOptionalParams(
          new ClassicUpload(bucket, new MockUploadModule(executor),
              glob, null /* legacy arg */, null /* legacy arg */))));

  project.getBuildersList().add(new Shell("echo foo > bar.txt"));
  // Fail the build to show that the uploader does nothing.
  project.getBuildersList().add(new FailureBuilder());
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.FAILURE, build.getResult());
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testStdoutUpload() throws Exception {
  underTest = new GoogleCloudStorageUploader(CREDENTIALS_ID,
      ImmutableList.<AbstractUpload>of(
          setOptionalParams(
              new StdoutUpload(bucket, new MockUploadModule(executor),
                  "build-log.txt", null /* legacy arg */))));

  project.getBuildersList().add(new Shell("echo Hello World!"));
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.SUCCESS, build.getResult());
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testFileGlob() throws Exception {
  glob = "*.txt";
  underTest = new GoogleCloudStorageUploader(CREDENTIALS_ID,
      ImmutableList.<AbstractUpload>of(setOptionalParams(
          new ClassicUpload(bucket, new MockUploadModule(executor),
              glob, null /* legacy arg */, null /* legacy arg */))));

  project.getBuildersList().add(new Shell("echo foo > bar.txt"));
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.SUCCESS, build.getResult());
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testAbsolutePath() throws Exception {
  String absoluteFilePath = "/tmp/bar.txt";
  glob = absoluteFilePath;
  underTest = new GoogleCloudStorageUploader(CREDENTIALS_ID,
      ImmutableList.<AbstractUpload>of(setOptionalParams(
          new ClassicUpload(bucket, new MockUploadModule(executor),
              glob, null /* legacy arg */, null /* legacy arg */))));

  project.getBuildersList().add(new Shell("echo foo > " +
      absoluteFilePath));
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.SUCCESS, build.getResult());
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testAbsoluteGlob() throws Exception {
  String absoluteFilePath1 = "/tmp/bar.1.txt";
  String absoluteFilePath2 = "/tmp/bar.2.txt";
  glob = "/tmp/bar.*.txt";
  underTest = new GoogleCloudStorageUploader(CREDENTIALS_ID,
      ImmutableList.<AbstractUpload>of(setOptionalParams(
          new ClassicUpload(bucket, new MockUploadModule(executor),
              glob, null /* legacy arg */, null /* legacy arg */))));

  project.getBuildersList().add(new Shell("echo foo > " +
      absoluteFilePath1));
  project.getBuildersList().add(new Shell("echo foo > " +
      absoluteFilePath2));
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.SUCCESS, build.getResult());
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testFileWithVar() throws Exception {
  glob = "bar.$BUILD_NUMBER.txt";
  underTest = new GoogleCloudStorageUploader(CREDENTIALS_ID,
      ImmutableList.<AbstractUpload>of(setOptionalParams(
          new ClassicUpload(bucket, new MockUploadModule(executor),
              glob, null /* legacy arg */, null /* legacy arg */))));

  project.getBuildersList().add(
      new Shell("echo foo > bar.$BUILD_NUMBER.txt"));
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.SUCCESS, build.getResult());
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testFileWithDir() throws Exception {
  glob = "blah/bar.txt";
  underTest = new GoogleCloudStorageUploader(CREDENTIALS_ID,
      ImmutableList.<AbstractUpload>of(setOptionalParams(
          new ClassicUpload(bucket, new MockUploadModule(executor),
              glob, null /* legacy arg */, null /* legacy arg */))));

  project.getBuildersList().add(
      new Shell("mkdir blah; echo foo > blah/bar.txt"));
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.SUCCESS, build.getResult());
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testFileWithRecursiveGlob() throws Exception {
  glob = "**/*.txt";
  underTest = new GoogleCloudStorageUploader(CREDENTIALS_ID,
      ImmutableList.<AbstractUpload>of(setOptionalParams(
          new ClassicUpload(bucket, new MockUploadModule(executor),
              glob, null /* legacy arg */, null /* legacy arg */))));

  project.getBuildersList().add(
      new Shell("mkdir blah; echo foo > blah/bar.txt"));
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.SUCCESS, build.getResult());
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testMultiFileGlob() throws Exception {
  glob = "*.txt";
  underTest = new GoogleCloudStorageUploader(CREDENTIALS_ID,
      ImmutableList.<AbstractUpload>of(setOptionalParams(
          new ClassicUpload(bucket, new MockUploadModule(executor),
              glob, null /* legacy arg */, null /* legacy arg */))));

  project.getBuildersList().add(
      new Shell("echo foo > foo.txt; echo bar > bar.txt"));
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.SUCCESS, build.getResult());
}
项目:lucene-search-plugin    文件:CommonTestCases.java   
public static void givenSearchWhenJobsWithBuildsAreExecutedThenTheyShouldBeSearchable(
        JenkinsSearchBackend jenkinsSearchBackend, JenkinsRule rule) throws IOException, ExecutionException,
        InterruptedException, SAXException, URISyntaxException, TimeoutException {
    assertEquals(0, jenkinsSearchBackend.search("echo").suggestions.size());
    FreeStyleProject project1 = rule.createFreeStyleProject("project1");
    project1.getBuildersList().add(new Shell("echo $BUILD_TAG\n"));
    // Building
    project1.scheduleBuild2(0).get();
    project1.scheduleBuild2(0).get();
    project1.scheduleBuild2(0).get();

    rule.createFreeStyleProject("project2");

    FreeStyleProject project3 = rule.createFreeStyleProject("project3");
    project3.getBuildersList().add(new Shell("cat $BUILD_TAG\n"));
    assertEquals(3, jenkinsSearchBackend.search("echo").suggestions.size());
    rebuildDatabase(jenkinsSearchBackend, rule);
    assertEquals(3, jenkinsSearchBackend.search("echo").suggestions.size());
}
项目:lucene-search-plugin    文件:CommonTestCases.java   
public static void givenSearchWhenIsNewItShouldSupportRebuildFromClean(JenkinsSearchBackend jenkinsSearchBackend,
        JenkinsRule rule) throws IOException, ExecutionException, InterruptedException, SAXException,
        URISyntaxException {
    try {
        assertEquals(0, jenkinsSearchBackend.search("echo").suggestions.size());
        rebuildDatabase(jenkinsSearchBackend, rule);
        assertEquals(0, jenkinsSearchBackend.search("echo").suggestions.size());
        FreeStyleProject project1 = rule.createFreeStyleProject("project1");
        project1.getBuildersList().add(new Shell("echo $BUILD_TAG\n"));
        // Building
        project1.scheduleBuild2(0).get();
        project1.scheduleBuild2(0).get();
        project1.scheduleBuild2(0).get();
        rebuildDatabase(jenkinsSearchBackend, rule);
        assertEquals(3, jenkinsSearchBackend.search("echo").suggestions.size());
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}
项目:yaml-project-plugin    文件:YamlToJsonTest.java   
@Test
public void testTagTranslations() throws Exception {
  YamlToJson underTest = new YamlToJson.Default(
      ImmutableList.<YamlTransform>of(
          new HelperTransform("!freestyle", FreeStyleProject.class),
          new HelperTransform("!maven", Maven.class),
          new HelperTransform("!git", GitSCM.class) {
            @Override
            public String construct(String value) {
              assertEquals("scm", value);
              return clazz.getName();
            }
          },
          new HelperTransform("!shell", Shell.class),
          new HelperTransform("!trigger", BuildTrigger.class),
          new HelperTransform("!mailer", Mailer.class)));
  for (String test : TAG_TESTS) {
    testOneTranslation(underTest, test);
  }
}
项目:yaml-project-plugin    文件:BinderTest.java   
@Test
public void testBindJob_WithBuilder() throws Exception {
  JSONObject json = (JSONObject) JSONSerializer.toJSON(EMPTY_JSON);

  JSONArray builders = (JSONArray) JSONSerializer.toJSON(BUILDERS1_JSON);
  json.put("builder", builders);

  Job job = underTest.bindJob(Jenkins.getInstance(), NAME, json);

  assertNotNull(job);
  assertThat(job, instanceOf(FreeStyleProject.class));
  assertEquals(NAME, job.getName());

  FreeStyleProject project = (FreeStyleProject) job;

  assertEquals(1, project.getBuilders().size());
  assertThat(project.getBuilders().get(0), instanceOf(Shell.class));
}
项目:yaml-project-plugin    文件:JsonToYamlTest.java   
@Test
public void testTagTranslations() throws Exception {
  JsonToYaml underTest = new JsonToYaml.Default(
      ImmutableList.<YamlTransform>of(
          new HelperTransform("!freestyle", FreeStyleProject.class),
          new HelperTransform("!maven", Maven.class),
          new HelperTransform("!git", GitSCM.class) {
            @Override
            public String represent(Class clazz) {
              assertEquals(this.clazz, clazz);
              return "scm";
            }
            @Override
            public String construct(String value) {
              assertEquals("scm", value);
              return this.clazz.getName();
            }
          },
          new HelperTransform("!shell", Shell.class),
          new HelperTransform("!trigger", BuildTrigger.class),
          new HelperTransform("!mailer", Mailer.class)));
  for (String test : TAG_TESTS) {
    testOneTranslation(underTest, test);
  }
}
项目:docker-plugin    文件:DockerComputerConnectorTest.java   
protected void should_connect_agent(DockerTemplate template) throws IOException, ExecutionException, InterruptedException {

        // FIXME on CI windows nodes don't have Docker4Windows
        Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);

        String dockerHost = SystemUtils.IS_OS_WINDOWS ? "tcp://localhost:2375" : "unix:///var/run/docker.sock";

        DockerCloud cloud = new DockerCloud("docker", new DockerAPI(new DockerServerEndpoint(dockerHost, null)),
                Collections.singletonList(template));

        j.jenkins.clouds.replaceBy(Collections.singleton(cloud));

        final FreeStyleProject project = j.createFreeStyleProject("test-docker-ssh");
        project.setAssignedLabel(Label.get("docker-agent"));
        project.getBuildersList().add(new Shell("whoami"));
        final FreeStyleBuild build = project.scheduleBuild2(0).get();
        Assert.assertTrue(build.getResult() == Result.SUCCESS);
        Assert.assertTrue(build.getLog().contains("jenkins"));
    }
项目:DotCi    文件:ShellScriptRunner.java   
public Result runScript(final ShellCommands commands) throws IOException, InterruptedException {
    Result r = Result.FAILURE;
    //Todo: use VitualChannel to figure out OS
    final String shellInterpreter = Functions.isWindows() ? "sh" : "/bin/bash";
    final Run run = this.buildExecutionContext.getRun();
    addExecutionInfoAction(run, commands);
    try {
        final Shell execution = new Shell("#!" + shellInterpreter + " -le \n" + commands.toShellScript());
        if (this.buildExecutionContext.performStep(execution, this.listener)) {
            r = Result.SUCCESS;
        }
    } catch (final InterruptedException e) {
        r = Executor.currentExecutor().abortResult();
        throw e;
    } finally {
        this.buildExecutionContext.setResult(r);
    }
    return r;
}
项目:credentials-binding-plugin    文件:BuildWrapperOrderCredentialsBindingTest.java   
@Issue("JENKINS-37871")
@Test public void secretBuildWrapperRunsBeforeNormalWrapper() throws Exception {
    StringCredentialsImpl firstCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "sample1", Secret.fromString(password));

    CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), firstCreds);

    SecretBuildWrapper wrapper = new SecretBuildWrapper(Arrays.asList(new StringBinding(bindingKey, credentialsId)));

    FreeStyleProject f = r.createFreeStyleProject("buildWrapperOrder");

    f.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_1%") : new Shell("echo $PASS_1"));
    f.getBuildWrappersList().add(new BuildWrapperOrder());
    f.getBuildWrappersList().add(wrapper);

    // configRoundtrip makes sure the ordinal of SecretBuildWrapper extension is applied correctly.
    r.configRoundtrip(f);

    FreeStyleBuild b = r.buildAndAssertSuccess(f);
    r.assertLogContains("Secret found!", b);
}
项目:credentials-binding-plugin    文件:UsernamePasswordBindingTest.java   
@Test public void basics() throws Exception {
    String username = "bob";
    String password = "s3cr3t";
    UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, null, "sample", username, password);
    CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
    FreeStyleProject p = r.createFreeStyleProject();
    p.getBuildWrappersList().add(new SecretBuildWrapper(Collections.<Binding<?>>singletonList(new UsernamePasswordBinding("AUTH", c.getId()))));
    p.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %AUTH% > auth.txt") : new Shell("echo $AUTH > auth.txt"));
    r.configRoundtrip(p);
    SecretBuildWrapper wrapper = p.getBuildWrappersList().get(SecretBuildWrapper.class);
    assertNotNull(wrapper);
    List<? extends MultiBinding<?>> bindings = wrapper.getBindings();
    assertEquals(1, bindings.size());
    MultiBinding<?> binding = bindings.get(0);
    assertEquals(c.getId(), binding.getCredentialsId());
    assertEquals(UsernamePasswordBinding.class, binding.getClass());
    assertEquals("AUTH", ((UsernamePasswordBinding) binding).getVariable());
    FreeStyleBuild b = r.buildAndAssertSuccess(p);
    r.assertLogNotContains(password, b);
    assertEquals(username + ':' + password, b.getWorkspace().child("auth.txt").readToString().trim());
    assertEquals("[AUTH]", b.getSensitiveBuildVariables().toString());
}
项目:jenkins-aws-bucket-credentials    文件:AwsBucketCredentialsBindingTest.java   
/**
 * this is an integration test as the bind is a bit tricky to mock out
 * @throws Exception
 */
@Test
public void bindAddsNoNewVariablesAndValuesYet() throws Exception{
    AwsBucketCredentialsImpl credentials = mock(AwsBucketCredentialsImpl.class);
    when(credentials.getId()).thenReturn("id");
    when(credentials.getPassword()).thenReturn(Secret.fromString("password"));
    when(credentials.getUsername()).thenReturn("username");
    CredentialsProvider.lookupStores(jenkinsRule.jenkins).iterator().next().addCredentials(Domain.global(), credentials);

    FreeStyleProject p = jenkinsRule.createFreeStyleProject();
    p.getBuildWrappersList().add(new SecretBuildWrapper(Collections.<MultiBinding<?>>singletonList(new AwsBucketCredentialsBinding("userid", "pass", "id"))));
    if (Functions.isWindows()) {
        p.getBuildersList().add(new BatchFile("@echo off\necho %userid%/%pass% > auth.txt"));
    } else {
        p.getBuildersList().add(new Shell("set +x\necho $userid/$pass > auth.txt"));
    }
    jenkinsRule.configRoundtrip((Item)p);
    SecretBuildWrapper wrapper = p.getBuildWrappersList().get(SecretBuildWrapper.class);
    assertThat(wrapper).isNotNull();
    List<? extends MultiBinding<?>> bindings = wrapper.getBindings();
    assertThat(bindings).hasSize(1);
    MultiBinding<?> binding = bindings.get(0);

    assertThat(((AwsBucketCredentialsBinding) binding).getUsernameVariable()).isEqualTo("userid");
    assertThat(((AwsBucketCredentialsBinding) binding).getPasswordVariable()).isEqualTo("pass");
    FreeStyleBuild b = jenkinsRule.buildAndAssertSuccess(p);
    assertThat(b.getWorkspace().child("auth.txt").readToString().trim()).contains("username/password");

}
项目:jenkins-deployment-manager-plugin    文件:GoogleCloudManagerBuildWrapperTest.java   
@Test
public void roundtripTest() throws Exception {
  GoogleCloudManagerBuildWrapper deployer = new GoogleCloudManagerBuildWrapper(
      // In this context, go ahead and test the full constructor rather
      // than use the helper method.
      new TemplatedCloudDeployment(CREDENTIALS_ID, DEPLOYMENT_NAME, CONFIG_FILE, IMPORT_PATHS,
          null));

  project.getBuildersList().add(new Shell("echo foo > bar.txt"));
  project.getBuildWrappersList().add(deployer);

  HtmlForm form = jenkins.createWebClient().getPage(project, "configure").getFormByName("config");

  assertEquals(CONFIG_FILE, form.<HtmlTextInput>getInputByName("_.configFilePath").getText());
  assertEquals(IMPORT_PATHS, form.<HtmlTextInput>getInputByName("_.importPaths").getText());
  assertEquals(DEPLOYMENT_NAME, form.<HtmlTextInput>getInputByName("_.deploymentName").getText());

  // Submit the form and check that the values match our original construction
  jenkins.submit(form);
  deployer = project.getBuildWrappersList().get(GoogleCloudManagerBuildWrapper.class);

  assertEquals(CONFIG_FILE,
      ((TemplatedCloudDeployment) deployer.getDeployment()).getConfigFilePath());
  assertEquals(IMPORT_PATHS,
      ((TemplatedCloudDeployment) deployer.getDeployment()).getImportPaths());
  assertEquals(DEPLOYMENT_NAME, deployer.getDeployment().getDeploymentName());
}
项目:jenkins-deployment-manager-plugin    文件:GoogleCloudManagerDeployerTest.java   
@Test
public void roundtripTest() throws Exception {
  final String deploymentFile = "path/to/the/file/named/foo";
  GoogleCloudManagerDeployer deployer = new GoogleCloudManagerDeployer(
      // In this context, go ahead and test the full constructor rather than
      // use the helper method.
      new TemplatedCloudDeployment(credentials.getId(), DEPLOYMENT_NAME, CONFIG_FILE,
          IMPORT_PATHS, null));

  project.getBuildersList().add(new Shell("echo foo > bar.txt"));
  project.getPublishersList().add(deployer);

  HtmlForm form = jenkins.createWebClient().getPage(project, "configure").getFormByName("config");

  System.out.println("HTMLForm form =\n" + form.toString());

  assertHasInputValue(form, "_.configFilePath", CONFIG_FILE);
  assertHasInputValue(form, "_.importPaths", IMPORT_PATHS);
  assertHasInputValue(form, "_.deploymentName", DEPLOYMENT_NAME);

  // Submit the form and check that the values match our original construction
  jenkins.submit(form);
  deployer = project.getPublishersList().get(GoogleCloudManagerDeployer.class);

  assertEquals(CONFIG_FILE,
      ((TemplatedCloudDeployment) deployer.getDeployment()).getConfigFilePath());
  assertEquals(IMPORT_PATHS,
      ((TemplatedCloudDeployment) deployer.getDeployment()).getImportPaths());
  assertEquals(DEPLOYMENT_NAME, deployer.getDeployment().getDeploymentName());
}
项目:jenkins-deployment-manager-plugin    文件:BuildStepDetailsProviderTest.java   
@Test
public void getDetails_Shell() {
  Shell shell = new Shell("ls -l");
  assertEquals(shell.getCommand(), BuildStepDetailsProvider.resolveDetails(shell));
  assertEquals(shell.getDescriptor().getDisplayName(),
      BuildStepDetailsProvider.resolveName(shell));
  assertEquals(ImmutableList.<String>of("ls", "-l"),
      BuildStepDetailsProvider.resolveFullCmd(shell));
}
项目:CI-Jenkins-Plugin    文件:ShellScript.java   
private int runShellCommands(List<String> cmds, OutputStream outputStream) throws Exception {
  FilePath tempFile;
  int result;
  ArgumentListBuilder args = new ArgumentListBuilder();
  tempFile = tempPath.createTextTempFile("script_" + tempPath.getBaseName() + new Date().getTime(), ".sh",
      prepareCommands(cmds, false), !tempPath.isRemote());
  final Shell.DescriptorImpl desciptor = (DescriptorImpl) Jenkins.getInstance().getDescriptor(Shell.class);
  final String interpretor = desciptor.getShellOrDefault(tempPath.getChannel());
  args.add(interpretor);
  args.add("-xe");
  args.add(tempFile.getRemote());
  result = launcher.launch().cmds(args).envs(env).stderr(logger).stdout(outputStream).pwd(tempPath).join();
  tempFile.delete();
  return result;
}
项目:parameter-pool-plugin    文件:ParameterPoolTest.java   
@Test
public void skipPoolValueFromFailedBuild() throws Exception {
    FreeStyleProject project = createProject(0, false);
    project.getBuildersList().add(new Shell("exit 1"));
    project.scheduleBuild2(0).waitForStart().run();

    FreeStyleBuild completedBuild = project.scheduleBuild2(0).get();

    String logText = FileUtils.readFileToString(completedBuild.getLogFile());
    assertThatVmIsInText(completedBuild.getNumber(), 2, logText);
}
项目:parameter-pool-plugin    文件:ParameterPoolTest.java   
@Test
public void pickFirstNonRunningValueIfAllValuesHaveFailed() throws Exception {
    FreeStyleProject project = createProject(0, false);
    project.getBuildersList().add(new Shell("exit 1"));
    project.scheduleBuild2(0).waitForStart().run();
    project.scheduleBuild2(0).waitForStart().run();
    project.scheduleBuild2(0).waitForStart().run();

    FreeStyleBuild completedBuild = project.scheduleBuild2(0).get();


    String logText = FileUtils.readFileToString(completedBuild.getLogFile());
    assertThatVmIsInText(completedBuild.getNumber(), 1, logText);
}
项目:parameter-pool-plugin    文件:ParameterPoolTest.java   
private FreeStyleProject createProject(int sleepDuration, boolean preferError) throws IOException {
    FreeStyleProject project = jenkins.createFreeStyleProject("test project");
    project.setConcurrentBuild(true);
    project.getBuildersList().add(new ParameterPoolBuilder(project.getName(), "testValue", "vm[1..3]", preferError));
    project.getBuildersList().add(new Shell("sleep " + sleepDuration + ";\necho Vm ${testValue} used for testing"));
    return project;
}
项目:yet-another-docker-plugin    文件:FreestyleTest.java   
@Override
        public Boolean call() throws Throwable {
            final Jenkins jenkins = Jenkins.getInstance();
            assertThat(image, notNullValue());

            // prepare job
            final FreeStyleProject project = jenkins.createProject(FreeStyleProject.class, "freestyle-dockerShell");
            final Shell env = new Shell("env");
            project.getBuildersList().add(env);

            DockerShellStep dockerShellStep = new DockerShellStep();
            dockerShellStep.setShellScript("env && pwd");
            dockerShellStep.getContainerLifecycle().setImage(image);
            dockerShellStep.setConnector(new CloudNameDockerConnector(DOCKER_CLOUD_NAME));
            project.getBuildersList().add(dockerShellStep);

//            project.setAssignedLabel(new LabelAtom(DOCKER_CLOUD_LABEL));
            project.save();

            LOG.trace("trace test.");
            project.scheduleBuild(new TestCause());

            // image pull may take time
            waitUntilNoActivityUpTo(jenkins, 10 * 60 * 1000);

            final FreeStyleBuild lastBuild = project.getLastBuild();
            assertThat(lastBuild, not(nullValue()));
            assertThat(lastBuild.getResult(), is(Result.SUCCESS));

            assertThat(getLog(lastBuild), Matchers.containsString("exit code: 0"));

            return true;
        }
项目:github-integration-plugin    文件:MatrixProjectITest.java   
@Test
public void testChildStatuses() throws Exception {
    final MatrixProject matrixProject = jRule.jenkins.createProject(MatrixProject.class, "matrix-project");

    matrixProject.addProperty(getPreconfiguredProperty(ghRule.getGhRepo()));
    matrixProject.addTrigger(getPreconfiguredPRTrigger());

    matrixProject.getBuildersList().add(new GitHubPRStatusBuilder());
    matrixProject.getBuildersList().add(new Shell("sleep 10"));

    matrixProject.getPublishersList().add(new GitHubPRBuildStatusPublisher());
    matrixProject.getPublishersList().add(new GitHubPRCommentPublisher(new GitHubPRMessage("Comment"), null, null));

    matrixProject.setAxes(
            new AxisList(
                    new TextAxis("first_axis", "first_value1", "first_value2"),
                    new TextAxis("second_axis", "sec_value1", "sec_value2")
            )
    );

    matrixProject.save();

    super.basicTest(matrixProject);

    for (MatrixBuild build : matrixProject.getBuilds()) {
        for (MatrixRun matrixRun : build.getRuns()) {
            jRule.assertLogNotContains("\tat", matrixRun);
        }
    }
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@SuppressWarnings("unchecked")
@Test
public void testFilePlain() throws Exception {
  project.getBuildersList().add(new Shell("echo foo > bar.txt"));
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class);
  executor.passThruWhen(Storage.Objects.Insert.class, checkFieldsMatch);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  dumpLog(build);
  assertEquals(Result.SUCCESS, build.getResult());
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@SuppressWarnings("unchecked")
@Test
public void testFilePlain_uploadFailed() throws Exception {
  project.getBuildersList().add(new Shell("echo foo > bar.txt"));
  project.getPublishersList().add(underTest);

  executor.throwWhen(Storage.Buckets.Get.class, forbiddenException);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.FAILURE, build.getResult());
  assertThat(CharStreams.toString(new InputStreamReader(
      build.getLogInputStream())), containsString("Forbidden"));
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testBadBucket() throws Exception {
  bucket = "bucket";
  underTest = new GoogleCloudStorageUploader(CREDENTIALS_ID,
      ImmutableList.<AbstractUpload>of(setOptionalParams(
          new ClassicUpload(bucket, new MockUploadModule(executor), glob,
              null /* legacy arg */, null /* legacy arg */))));

  project.getBuildersList().add(new Shell("echo foo > bar.txt"));
  project.getPublishersList().add(underTest);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.FAILURE, build.getResult());
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testNoFileFailure() throws Exception {
  project.getBuildersList().add(new Shell("echo foo > foo.txt"));
  project.getPublishersList().add(underTest);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.SUCCESS, build.getResult());

  dumpLog(build);
  assertThat(CharStreams.toString(new InputStreamReader(
      build.getLogInputStream())), containsString(
      Messages.ClassicUpload_NoArtifacts(glob)));
}
项目:google-storage-plugin    文件:GoogleCloudStorageUploaderTest.java   
@Test
public void testFilePlainWithFailure() throws Exception {
  project.getBuildersList().add(new Shell("echo foo > bar.txt"));
  // Fail the build to show that the uploader does nothing.
  project.getBuildersList().add(new FailureBuilder());
  project.getPublishersList().add(underTest);

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  assertEquals(Result.FAILURE, build.getResult());
}
项目:Spirent-iTest-Jenkins-Plugin    文件:ITest.java   
/**
 * Return correct CommandInterpreter based on OS  
 * 
 * @param launcher
 * @param script
 * @return CommandInterpreter
 */
private CommandInterpreter getCommandInterpreter(final Launcher launcher,
        final String script) {
    if (launcher.isUnix())
        return new Shell(script);
    else
        return new BatchFile(script);
}
项目:yaml-project-plugin    文件:BinderTest.java   
@Test
public void testBind_DataBoundConstructor() throws Exception {
  JSONObject json = (JSONObject) JSONSerializer.toJSON(SHELL_JSON);
  Shell shell = underTest.bind(json);
  assertNotNull(shell);
  // Test that the data came through
  assertEquals("echo Hello World", shell.getCommand());
}