hudson.model.FreeStyleBuild Java Examples
The following examples show how to use
hudson.model.FreeStyleBuild.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 8 votes |
@Test public void findPipelineRunsForAPipelineTest() throws Exception { FreeStyleProject p1 = j.createFreeStyleProject("pipeline1"); FreeStyleProject p2 = j.createFreeStyleProject("pipeline2"); p1.getBuildersList().add(new Shell("echo hello!\nsleep 1")); p2.getBuildersList().add(new Shell("echo hello!\nsleep 1")); Stack<FreeStyleBuild> builds = new Stack<FreeStyleBuild>(); FreeStyleBuild b11 = p1.scheduleBuild2(0).get(); FreeStyleBuild b12 = p1.scheduleBuild2(0).get(); builds.push(b11); builds.push(b12); j.assertBuildStatusSuccess(b11); j.assertBuildStatusSuccess(b12); List<Map> resp = get("/search?q=type:run;organization:jenkins;pipeline:pipeline1", List.class); assertEquals(builds.size(), resp.size()); for(int i=0; i< builds.size(); i++){ Map p = resp.get(i); FreeStyleBuild b = builds.pop(); validateRun(b, p); } }
Example #2
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void getPipelineRunLatestTest() throws Exception { FreeStyleProject p = j.createFreeStyleProject("pipeline5"); p.getBuildersList().add(new Shell("echo hello!\nsleep 1")); FreeStyleBuild b = p.scheduleBuild2(0).get(); j.assertBuildStatusSuccess(b); List<Map> resp = get("/search?q=type:run;organization:jenkins;pipeline:pipeline5;latestOnly:true", List.class); Run[] run = {b}; assertEquals(run.length, resp.size()); for(int i=0; i<run.length; i++){ Map lr = resp.get(i); validateRun(run[i], lr); } }
Example #3
Source File: PhabricatorNotifierTest.java From phabricator-jenkins-plugin with MIT License | 6 votes |
@Test public void testPostUnitWithFailure() throws Exception { TestUtils.addCopyBuildStep(p, TestUtils.JUNIT_XML, JUnitTestProvider.class, "go-torch-junit-fail.xml"); p.getPublishersList().add(TestUtils.getDefaultXUnitPublisher()); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject()); assertEquals(Result.UNSTABLE, build.getResult()); assertLogContains("Publishing unit results to Harbormaster for 8 tests", build); FakeConduit conduitTestClient = getConduitClient(); // There are two requests, first it fetches the diff info, secondly it posts the unit result to harbormaster assertEquals(2, conduitTestClient.getRequestBodies().size()); String actualUnitResultWithFailureRequestBody = conduitTestClient.getRequestBodies().get(1); assertConduitRequest(getUnitResultWithFailureRequest(), actualUnitResultWithFailureRequestBody); }
Example #4
Source File: DockerComputerConnectorTest.java From docker-plugin with MIT License | 6 votes |
protected void should_connect_agent(DockerTemplate template) throws IOException, ExecutionException, InterruptedException, TimeoutException { // 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(cloudName, 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(LABEL)); project.getBuildersList().add(new Shell("whoami")); final QueueTaskFuture<FreeStyleBuild> scheduledBuild = project.scheduleBuild2(0); try { final FreeStyleBuild build = scheduledBuild.get(60L, TimeUnit.SECONDS); Assert.assertTrue(build.getResult() == Result.SUCCESS); Assert.assertTrue(build.getLog().contains("jenkins")); } finally { scheduledBuild.cancel(true); } }
Example #5
Source File: DockerRunFingerprintFacetTest.java From docker-commons-plugin with MIT License | 6 votes |
@Test public void test_readResolve() throws Exception { FreeStyleProject p = rule.createFreeStyleProject("test"); FreeStyleBuild b = rule.assertBuildStatusSuccess(p.scheduleBuild2(0)); ContainerRecord r1 = new ContainerRecord("192.168.1.10", "cid", IMAGE_ID, "magic", System.currentTimeMillis(), Collections.<String, String>emptyMap()); DockerFingerprints.addRunFacet(r1, b); Fingerprint fingerprint = DockerFingerprints.of(IMAGE_ID); DockerRunFingerprintFacet facet = new DockerRunFingerprintFacet(fingerprint, System.currentTimeMillis(), IMAGE_ID); ContainerRecord r2 = new ContainerRecord("192.168.1.10", "cid", null, "magic", System.currentTimeMillis(), Collections.<String, String>emptyMap()); facet.add(r2); Assert.assertNull(r2.getImageId()); facet.readResolve(); Assert.assertEquals(IMAGE_ID, r2.getImageId()); // Check that actions have been automatically added DockerFingerprintAction fpAction = b.getAction(DockerFingerprintAction.class); Assert.assertNotNull("DockerFingerprintAction should be added automatically", fpAction); Assert.assertTrue("Docker image should be referred in the action", fpAction.getImageIDs().contains(IMAGE_ID)); }
Example #6
Source File: BuildResultProcessorTest.java From phabricator-jenkins-plugin with MIT License | 6 votes |
private BuildResultProcessor runProcessLintViolationsTest(String lintFileContent, ConduitAPIClient conduitAPIClient) throws Exception { final String fileName = ".phabricator-lint"; project.getBuildersList().add(echoBuilder(fileName, lintFileContent)); FreeStyleBuild build = getBuild(); BuildResultProcessor processor = new BuildResultProcessor( TestUtils.getDefaultLogger(), build, build.getWorkspace(), mock(Differential.class), new DifferentialClient(null, conduitAPIClient), TestUtils.TEST_PHID, mock(CodeCoverageMetrics.class), TestUtils.TEST_BASE_URL, true, new CoverageCheckSettings(true, 0.0, 100.0) ); processor.processLintResults(fileName, "1000"); processor.processHarbormaster(); return processor; }
Example #7
Source File: DockerSimpleBuildWrapperTest.java From yet-another-docker-plugin with MIT License | 6 votes |
@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(); }
Example #8
Source File: DockerContainerITest.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Runs a make file to compile a cpp file on a docker container agent. * * @throws IOException * When the node assignment of the agent fails. * @throws InterruptedException * If the creation of the docker container fails. */ @Test public void shouldBuildMakefileOnAgent() throws IOException, InterruptedException { assumeThat(isWindows()).as("Running on Windows").isFalse(); DumbSlave agent = createDockerContainerAgent(gccDockerRule.get()); FreeStyleProject project = createFreeStyleProject(); project.setAssignedNode(agent); createFileInAgentWorkspace(agent, project, "test.cpp", getSampleCppFile()); createFileInAgentWorkspace(agent, project, "makefile", getSampleMakefileFile()); project.getBuildersList().add(new Shell("make")); enableWarnings(project, createTool(new Gcc4(), "")); scheduleSuccessfulBuild(project); FreeStyleBuild lastBuild = project.getLastBuild(); AnalysisResult result = getAnalysisResult(lastBuild); assertThat(result).hasTotalSize(1); assertThat(lastBuild.getBuiltOn().getLabelString()).isEqualTo(((Node) agent).getLabelString()); }
Example #9
Source File: ProxyTest.java From appcenter-plugin with MIT License | 6 votes |
@Test public void should_SendProxyAuthorizationHeader_When_ProxyCredentialsConfigured() throws Exception { // Given final String userName = "user"; final String password = "password"; jenkinsRule.jenkins.proxy = new ProxyConfiguration(proxyWebServer.getHostName(), proxyWebServer.getPort(), userName, password); MockWebServerUtil.enqueueProxyAuthRequired(proxyWebServer); // first request rejected and proxy authentication requested MockWebServerUtil.enqueueSuccess(proxyWebServer); // When final FreeStyleBuild freeStyleBuild = freeStyleProject.scheduleBuild2(0).get(); // Then jenkinsRule.assertBuildStatus(Result.SUCCESS, freeStyleBuild); assertThat(proxyWebServer.getRequestCount()).isEqualTo(5); assertThat(mockWebServer.getRequestCount()).isEqualTo(0); // proxy auth is performed on second request assertThat(proxyWebServer.takeRequest().getHeader(HttpHeaders.PROXY_AUTHORIZATION)).isNull(); assertThat(proxyWebServer.takeRequest().getHeader(HttpHeaders.PROXY_AUTHORIZATION)).isEqualTo(Credentials.basic(userName, password)); }
Example #10
Source File: EnvInterpolationTest.java From appcenter-plugin with MIT License | 6 votes |
@Test public void should_InterpolateEnv_InDestinationGroups() throws Exception { // Given MockWebServerUtil.enqueueSuccessWithSymbols(mockWebServer); // When final FreeStyleBuild freeStyleBuild = freeStyleProject.scheduleBuild2(0).get(); // Then jenkinsRule.assertBuildStatus(Result.SUCCESS, freeStyleBuild); mockWebServer.takeRequest(); mockWebServer.takeRequest(); mockWebServer.takeRequest(); mockWebServer.takeRequest(); mockWebServer.takeRequest(); mockWebServer.takeRequest(); final RecordedRequest recordedRequest = mockWebServer.takeRequest(); assertThat(recordedRequest.getBody().readUtf8()).contains("[{\"name\":\"casey\"},{\"name\":\"niccoli\"}]"); }
Example #11
Source File: RemoteFileFetcherTest.java From phabricator-jenkins-plugin with MIT License | 6 votes |
private void testWithContent(String content, String len) throws Exception { final String fileName = "just-a-test.txt"; project.getBuildersList().add(echoBuilder(fileName, content)); FreeStyleBuild build = getBuild(); RemoteFileFetcher fetcher = new RemoteFileFetcher( build.getWorkspace(), logger, fileName, len ); assertEquals(content, fetcher.getRemoteFile()); fetcher = new RemoteFileFetcher( build.getWorkspace(), logger, "*.txt", len ); assertEquals(content, fetcher.getRemoteFile()); }
Example #12
Source File: JUnitResultArchiverTest.java From junit-plugin with MIT License | 6 votes |
private void assertTestResults(FreeStyleBuild build) { TestResultAction testResultAction = build.getAction(TestResultAction.class); assertNotNull("no TestResultAction", testResultAction); TestResult result = testResultAction.getResult(); assertNotNull("no TestResult", result); assertEquals("should have 1 failing test", 1, testResultAction.getFailCount()); assertEquals("should have 1 failing test", 1, result.getFailCount()); assertEquals("should have 132 total tests", 132, testResultAction.getTotalCount()); assertEquals("should have 132 total tests", 132, result.getTotalCount()); for (SuiteResult suite : result.getSuites()) { assertNull("No nodeId should be present on the SuiteResult", suite.getNodeId()); } }
Example #13
Source File: UsernamePasswordBindingTest.java From credentials-binding-plugin with MIT License | 6 votes |
@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()); }
Example #14
Source File: RemoteFileFetcherTest.java From phabricator-jenkins-plugin with MIT License | 6 votes |
@Test public void testNoCommentConfigured() throws Exception { FreeStyleBuild build = getBuild(); RemoteFileFetcher fetcher = new RemoteFileFetcher( build.getWorkspace(), logger, "", "1000" ); assertNull(fetcher.getRemoteFile()); fetcher = new RemoteFileFetcher( build.getWorkspace(), logger, "non-existent", "1000" ); assertNull(fetcher.getRemoteFile()); }
Example #15
Source File: TestResultLinksTest.java From junit-plugin with MIT License | 6 votes |
@LocalData @Test public void testNonDescendantRelativePath() throws Exception { FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.MINUTES); // leave time for interactive debugging rule.assertBuildStatus(Result.UNSTABLE, build); TestResult theOverallTestResult = build.getAction(TestResultAction.class).getResult(); CaseResult theFailedTestCase = theOverallTestResult.getFailedTests().get(0); String relativePath = theFailedTestCase.getRelativePathFrom(theOverallTestResult); System.out.println("relative path seems to be: " + relativePath); assertNotNull("relative path exists", relativePath); assertFalse("relative path doesn't start with a slash", relativePath.startsWith("/")); // Now ask for the relative path from the child to the parent -- we should get an absolute path String relativePath2 = theOverallTestResult.getRelativePathFrom(theFailedTestCase); System.out.println("relative path2 seems to be: " + relativePath2); // I know that in a HudsonTestCase we don't have a meaningful root url, so I expect an empty string here. // If somehow we start being able to produce a root url, then I'll also tolerate a url that starts with that. boolean pathIsEmptyOrNull = relativePath2 == null || relativePath2.isEmpty(); boolean pathStartsWithRootUrl = !pathIsEmptyOrNull && relativePath2.startsWith(rule.jenkins.getRootUrl()); assertTrue("relative path is empty OR begins with the app root", pathIsEmptyOrNull || pathStartsWithRootUrl ); }
Example #16
Source File: StatePreloaderTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void test() throws IOException, ExecutionException, InterruptedException, SAXException { // Create a project and run a build on it. FreeStyleProject freestyleProject = j.createProject(FreeStyleProject.class, "freestyle"); FreeStyleBuild run = freestyleProject.scheduleBuild2(0).get(); j.waitForCompletion(run); // Lets request the activity page for that project. The page should // contain some prefetched javascript for the pipeline // details + the runs on the page Assert.assertTrue(BlueOceanUrlMapper.all().size()> 0); BlueOceanUrlMapper mapper = BlueOceanUrlMapper.all().get(0); String projectBlueUrl = j.jenkins.getRootUrl() + mapper.getUrl(freestyleProject); Document doc = Jsoup.connect(projectBlueUrl + "/activity/").get(); String script = doc.select("head script").toString(); Assert.assertTrue(script.contains(String.format("setState('prefetchdata.%s',", PipelineStatePreloader.class.getSimpleName()))); Assert.assertTrue(script.contains(String.format("setState('prefetchdata.%s',", PipelineActivityStatePreloader.class.getSimpleName()))); Assert.assertTrue(script.contains("\"restUrl\":\"/blue/rest/organizations/jenkins/pipelines/freestyle/runs/?start=0&limit=26\"")); }
Example #17
Source File: PhabricatorNotifierTest.java From phabricator-jenkins-plugin with MIT License | 6 votes |
@Test public void testPassBuildOnDecreasedCoverageButGreaterThanMinPercent() throws Exception { TestUtils.addCopyBuildStep(p, TestUtils.COBERTURA_XML, XmlCoverageProvider.class, "go-torch-coverage2.xml"); UberallsClient uberalls = TestUtils.getDefaultUberallsClient(); notifier = getNotifierWithCoverageCheck(0.0, 90.0); when(uberalls.getCoverage(any(String.class))).thenReturn("{\n" + " \"sha\": \"deadbeef\",\n" + " \"lineCoverage\": 100,\n" + " \"filesCoverage\": 100,\n" + " \"packageCoverage\": 100,\n" + " \"classesCoverage\": 100,\n" + " \"methodCoverage\": 100,\n" + " \"conditionalCoverage\": 100,\n" + " \"linesCovered\": 100,\n" + " \"linesTested\": 100\n" + "}"); notifier.getDescriptor().setUberallsURL("http://uber.alls"); notifier.setUberallsClient(uberalls); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject()); assertEquals(Result.SUCCESS, build.getResult()); }
Example #18
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void findPipelineRunsForAllPipelineTest() throws IOException, ExecutionException, InterruptedException { FreeStyleProject p1 = j.createFreeStyleProject("pipeline11"); FreeStyleProject p2 = j.createFreeStyleProject("pipeline22"); p1.getBuildersList().add(new Shell("echo hello!\nsleep 1")); p2.getBuildersList().add(new Shell("echo hello!\nsleep 1")); Stack<FreeStyleBuild> p1builds = new Stack<FreeStyleBuild>(); p1builds.push(p1.scheduleBuild2(0).get()); p1builds.push(p1.scheduleBuild2(0).get()); Stack<FreeStyleBuild> p2builds = new Stack<FreeStyleBuild>(); p2builds.push(p2.scheduleBuild2(0).get()); p2builds.push(p2.scheduleBuild2(0).get()); Map<String, Stack<FreeStyleBuild>> buildMap = ImmutableMap.of(p1.getName(), p1builds, p2.getName(), p2builds); List<Map> resp = get("/search?q=type:run;organization:jenkins", List.class); assertEquals(4, resp.size()); for(int i=0; i< 4; i++){ Map p = resp.get(i); String pipeline = (String) p.get("pipeline"); assertNotNull(pipeline); validateRun(buildMap.get(pipeline).pop(), p); } }
Example #19
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void findAllPipelineTest() throws IOException, ExecutionException, InterruptedException { MockFolder folder1 = j.createFolder("folder1"); j.createFolder("afolder"); Project p1 = folder1.createProject(FreeStyleProject.class, "test1"); MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2"); folder1.createProject(MockFolder.class, "folder3"); folder2.createProject(FreeStyleProject.class, "test2"); FreeStyleBuild b1 = (FreeStyleBuild) p1.scheduleBuild2(0).get(); List<Map> resp = get("/search?q=type:pipeline", List.class); assertEquals(6, resp.size()); }
Example #20
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void getPipelinesTest() throws Exception { Project p2 = j.createFreeStyleProject("pipeline2"); Project p1 = j.createFreeStyleProject("pipeline1"); List<Map> responses = get("/search/?q=type:pipeline", List.class); assertEquals(2, responses.size()); validatePipeline(p1, responses.get(0)); validatePipeline(p2, responses.get(1)); p1.getBuildersList().add(new Shell("echo hello!\nsleep 1")); FreeStyleBuild b = (FreeStyleBuild) p1.scheduleBuild2(0).get(); j.assertBuildStatusSuccess(b); }
Example #21
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void getFreeStyleJobTest() throws Exception { Project p1 = j.createFreeStyleProject("pipeline1"); Project p2 = j.createFreeStyleProject("pipeline2"); p1.getBuildersList().add(new Shell("echo hello!\nsleep 1")); FreeStyleBuild b = (FreeStyleBuild) p1.scheduleBuild2(0).get(); j.assertBuildStatusSuccess(b); List<Map> resp = get("/organizations/jenkins/pipelines/", List.class); Project[] projects = {p1,p2}; assertEquals(projects.length, resp.size()); for(int i=0; i<projects.length; i++){ Map p = resp.get(i); validatePipeline(projects[i], p); } }
Example #22
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void getPipelineRunWithTestResult() throws Exception { FreeStyleProject p = j.createFreeStyleProject("pipeline4"); p.getBuildersList().add(new Shell("echo '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<testsuite xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd\" name=\"io.jenkins.blueocean.jsextensions.JenkinsJSExtensionsTest\" time=\"35.7\" tests=\"1\" errors=\"0\" skipped=\"0\" failures=\"0\">\n" + " <properties>\n" + " </properties>\n" + " <testcase name=\"test\" classname=\"io.jenkins.blueocean.jsextensions.JenkinsJSExtensionsTest\" time=\"34.09\"/>\n" + "</testsuite>' > test-result.xml")); p.getPublishersList().add(new JUnitResultArchiver("*.xml")); FreeStyleBuild b = p.scheduleBuild2(0).get(); TestResultAction resultAction = b.getAction(TestResultAction.class); assertEquals("io.jenkins.blueocean.jsextensions.JenkinsJSExtensionsTest",resultAction.getResult().getSuites().iterator().next().getName()); j.assertBuildStatusSuccess(b); Map resp = get("/organizations/jenkins/pipelines/pipeline4/runs/"+b.getId()); //discover TestResultAction super classes get("/classes/hudson.tasks.junit.TestResultAction/"); // get junit rest report get("/organizations/jenkins/pipelines/pipeline4/runs/"+b.getId()+"/testReport/result/"); }
Example #23
Source File: DefaultGitHubNotificationStrategyTest.java From github-branch-source-plugin with MIT License | 6 votes |
@Test public void given_jobOrRun_then_differentURLs() throws Exception { List<GitHubSCMSource> srcs = Arrays.asList( new GitHubSCMSource("example", "test", null, false), new GitHubSCMSource("", "", "http://github.com/example/test", true) ); for( GitHubSCMSource src: srcs) { FreeStyleProject job = j.createFreeStyleProject(); FreeStyleBuild run = j.buildAndAssertSuccess(job); DefaultGitHubNotificationStrategy instance = new DefaultGitHubNotificationStrategy(); String urlA = instance.notifications(GitHubNotificationContext.build(null, run, src, new BranchSCMHead("master")), new LogTaskListener(Logger.getLogger(getClass().getName()), Level.INFO)).get(0).getUrl(); String urlB = instance.notifications(GitHubNotificationContext.build(job, null, src, new BranchSCMHead("master")), new LogTaskListener(Logger.getLogger(getClass().getName()), Level.INFO)).get(0).getUrl(); assertNotEquals(urlA, urlB); } }
Example #24
Source File: VaultConfigurationIT.java From hashicorp-vault-plugin with MIT License | 5 votes |
@Test public void shouldFailIfCredentialsDoNotExist() throws Exception { GlobalVaultConfiguration globalConfig = GlobalConfiguration.all() .get(GlobalVaultConfiguration.class); assertThat(globalConfig, is(notNullValue())); VaultConfiguration vaultConfig = new VaultConfiguration(); vaultConfig.setVaultUrl("http://example.com"); vaultConfig.setVaultCredentialId("some-made-up-ID"); vaultConfig.setFailIfNotFound(false); vaultConfig.setVaultNamespace("mynamespace"); vaultConfig.setTimeout(TIMEOUT); globalConfig.setConfiguration(vaultConfig); globalConfig.save(); List<VaultSecret> secrets = standardSecrets(); VaultBuildWrapper vaultBuildWrapper = new VaultBuildWrapper(secrets); VaultAccessor mockAccessor = mockVaultAccessor(GLOBAL_ENGINE_VERSION_2); vaultBuildWrapper.setVaultAccessor(mockAccessor); this.project.getBuildWrappersList().add(vaultBuildWrapper); this.project.getBuildersList().add(echoSecret()); FreeStyleBuild build = this.project.scheduleBuild2(0).get(); jenkins.assertBuildStatus(Result.FAILURE, build); VaultConfig config = new VaultConfig().address(anyString()); mockAccessor.setConfig(config); mockAccessor.setCredential(any(VaultCredential.class)); verify(mockAccessor, times(0)).init(); verify(mockAccessor, times(0)).read(anyString(), anyInt()); jenkins.assertLogContains("CredentialsUnavailableException", build); }
Example #25
Source File: FreestyleTest.java From yet-another-docker-plugin with MIT License | 5 votes |
@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; }
Example #26
Source File: DollarSecretPatternFactoryTest.java From credentials-binding-plugin with MIT License | 5 votes |
@Issue("JENKINS-24805") @Test public void maskingFreeStyleSecrets() throws Exception { String firstCredentialsId = "creds_1"; String firstPassword = "a$build"; StringCredentialsImpl firstCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, firstCredentialsId, "sample1", Secret.fromString(firstPassword)); CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), firstCreds); String secondCredentialsId = "creds_2"; String secondPassword = "a$$b"; StringCredentialsImpl secondCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, secondCredentialsId, "sample2", Secret.fromString(secondPassword)); CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), secondCreds); SecretBuildWrapper wrapper = new SecretBuildWrapper(Arrays.asList(new StringBinding("PASS_1", firstCredentialsId), new StringBinding("PASS_2", secondCredentialsId))); FreeStyleProject project = r.createFreeStyleProject(); project.setConcurrentBuild(true); project.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_1%") : new Shell("echo \"$PASS_1\"")); project.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_2%") : new Shell("echo \"$PASS_2\"")); project.getBuildersList().add(new Maven("$PASS_1 $PASS_2", "default")); project.getBuildWrappersList().add(wrapper); r.configRoundtrip((Item)project); QueueTaskFuture<FreeStyleBuild> future = project.scheduleBuild2(0); FreeStyleBuild build = future.get(); r.assertLogNotContains(firstPassword, build); r.assertLogNotContains(firstPassword.replace("$", "$$"), build); r.assertLogNotContains(secondPassword, build); r.assertLogNotContains(secondPassword.replace("$", "$$"), build); r.assertLogContains("****", build); }
Example #27
Source File: FreeStyleProjectTest.java From lockable-resources-plugin with MIT License | 5 votes |
@Test @Issue("JENKINS-34853") public void security170fix() throws Exception { LockableResourcesManager.get().createResource("resource1"); FreeStyleProject p = j.createFreeStyleProject("p"); p.addProperty(new RequiredResourcesProperty("resource1", "resourceNameVar", null, null, null)); p.getBuildersList().add(new PrinterBuilder()); FreeStyleBuild b1 = p.scheduleBuild2(0).get(); j.assertLogContains("resourceNameVar: resource1", b1); j.assertBuildStatus(Result.SUCCESS, b1); }
Example #28
Source File: PhabricatorBuildWrapperTest.java From phabricator-jenkins-plugin with MIT License | 5 votes |
@Test public void getAbortOnRevisionIdIfAvailable() throws Exception { FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, null, true); assertNull(PhabricatorBuildWrapper.getAbortOnRevisionId(build)); List<ParameterValue> parameters = Lists.newArrayList(); parameters.add(new ParameterValue("ABORT_ON_REVISION_ID") { @Override public Object getValue() { return "test"; } }); build.addAction(new ParametersAction(parameters)); assertEquals("test", PhabricatorBuildWrapper.getAbortOnRevisionId(build)); }
Example #29
Source File: ProxyTest.java From appcenter-plugin with MIT License | 5 votes |
@Test public void should_SendRequestsToProxy_When_ProxyConfigurationFound() throws Exception { // Given jenkinsRule.jenkins.proxy = new ProxyConfiguration(proxyWebServer.getHostName(), proxyWebServer.getPort()); MockWebServerUtil.enqueueSuccess(proxyWebServer); // When final FreeStyleBuild freeStyleBuild = freeStyleProject.scheduleBuild2(0).get(); // Then jenkinsRule.assertBuildStatus(Result.SUCCESS, freeStyleBuild); assertThat(proxyWebServer.getRequestCount()).isEqualTo(4); assertThat(mockWebServer.getRequestCount()).isEqualTo(0); }
Example #30
Source File: BuildPageRedirectActionTest.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
@Test public void redirectToBuildStatusUrl() throws IOException, ExecutionException, InterruptedException, TimeoutException { FreeStyleProject testProject = jenkins.createFreeStyleProject(); testProject.setScm(new GitSCM(gitRepoUrl)); testProject.setQuietPeriod(0); QueueTaskFuture<FreeStyleBuild> future = testProject.scheduleBuild2(0); FreeStyleBuild build = future.get(15, TimeUnit.SECONDS); doThrow(IOException.class).when(response).sendRedirect2(jenkins.getInstance().getRootUrl() + build.getUrl()); getBuildPageRedirectAction(testProject).execute(response); verify(response).sendRedirect2(jenkins.getInstance().getRootUrl() + build.getBuildStatusUrl()); }