org.jenkinsci.plugins.workflow.job.WorkflowRun Java Examples
The following examples show how to use
org.jenkinsci.plugins.workflow.job.WorkflowRun.
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: S3PresignUrlStepTests.java From pipeline-aws-plugin with Apache License 2.0 | 7 votes |
@Test public void presignWithCustomMethod() throws Exception { WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "s3PresignTest"); job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " def url = s3PresignURL(bucket: 'foo', key: 'bar', httpMethod: 'POST')\n" + " echo \"url=$url\"\n" + "}\n", true) ); String urlString = "http://localhost:283/sdkd"; URL url = new URL(urlString); Mockito.when(this.s3.generatePresignedUrl(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(url); WorkflowRun run = this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0)); jenkinsRule.assertLogContains("url=" + urlString, run); ArgumentCaptor<Date> expirationCaptor = ArgumentCaptor.forClass(Date.class); Mockito.verify(s3).generatePresignedUrl(Mockito.eq("foo"), Mockito.eq("bar"), Mockito.any(), Mockito.eq(HttpMethod.POST)); }
Example #2
Source File: TeeStepTest.java From pipeline-utility-steps-plugin with MIT License | 6 votes |
@Test @Issue({"JENKINS-54346", "JENKINS-55505"}) public void closed() throws Exception { rr.then(r -> { r.createSlave("remote", null, null); WorkflowJob p = r.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition( "node('remote') {\n" + " tee('x.log') {\n" + " echo 'first message'\n" + " }\n" + " if (isUnix()) {sh 'rm x.log'} else {bat 'del x.log'}\n" + " writeFile file: 'x.log', text: 'second message'\n" + " echo(/got: ${readFile('x.log').trim().replaceAll('\\\\s+', ' ')}/)\n" + "}", true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); r.assertBuildStatus(Result.SUCCESS, r.waitForCompletion(b)); r.assertLogContains("got: second message", b); }); }
Example #3
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void getPipelineJobRuns() throws Exception { WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1"); job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build1'); " + " echo ('Building'); " + " stage ('Test1'); " + " sleep 10000 " + " echo ('Testing'); " + "}")); job1.setConcurrentBuild(false); WorkflowRun r = job1.scheduleBuild2(0).waitForStart(); job1.scheduleBuild2(0); List l = request().get("/organizations/jenkins/pipelines/pipeline1/runs").build(List.class); Assert.assertEquals(2, l.size()); Assert.assertEquals("io.jenkins.blueocean.service.embedded.rest.QueuedBlueRun", ((Map) l.get(0)).get("_class")); Assert.assertEquals("io.jenkins.blueocean.rest.impl.pipeline.PipelineRunImpl", ((Map) l.get(1)).get("_class")); }
Example #4
Source File: BranchNameIssueKeyExtractor.java From atlassian-jira-software-cloud-plugin with Apache License 2.0 | 6 votes |
@Override public Set<String> extractIssueKeys(final WorkflowRun build) { // The action is only injected for Multibranch Pipeline jobs // The action is not injected for Pipeline (single branch) jobs final SCMRevisionAction scmAction = build.getAction(SCMRevisionAction.class); if (scmAction == null) { logger.debug("SCMRevisionAction is null"); return Collections.emptySet(); } final SCMRevision revision = scmAction.getRevision(); final ScmRevision scmRevision = new ScmRevision(revision.getHead().getName()); return extractIssueKeys(scmRevision); }
Example #5
Source File: CertificateMultiBindingTest.java From credentials-binding-plugin with MIT License | 6 votes |
@Test public void basicsPipeline() throws Exception { // create the Credentials String alias = "androiddebugkey"; String password = "android"; StandardCertificateCredentials c = new CertificateCredentialsImpl(CredentialsScope.GLOBAL, "my-certificate", alias, password, new CertificateCredentialsImpl.FileOnMasterKeyStoreSource(certificate.getAbsolutePath())); CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c); // create the Pipeline job WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); String pipelineScript = IOUtils.toString(getTestResourceInputStream("basicsPipeline-Jenkinsfile")); p.setDefinition(new CpsFlowDefinition(pipelineScript, true)); // copy resources into workspace FilePath workspace = r.jenkins.getWorkspaceFor(p); copyTestResourceIntoWorkspace(workspace, "basicsPipeline-step1.bat", 0755); copyTestResourceIntoWorkspace(workspace, "basicsPipeline-step2.bat", 0755); copyTestResourceIntoWorkspace(workspace, "basicsPipeline-step1.sh", 0755); copyTestResourceIntoWorkspace(workspace, "basicsPipeline-step2.sh", 0755); // execute the pipeline WorkflowRun b = p.scheduleBuild2(0).waitForStart(); r.waitForCompletion(b); r.assertBuildStatusSuccess(b); }
Example #6
Source File: ZipFileBindingTest.java From credentials-binding-plugin with MIT License | 6 votes |
@Issue("JENKINS-30941") @Test public void cleanUpSucceeds() throws Exception { /** Issue was just present on Linux not windows - but the test will run on both */ final String credentialsId = "zipfile"; FileCredentialsImpl fc = new FileCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "Just a zip file", "a.zip", SecretBytes.fromBytes(IOUtils.toByteArray(ZipFileBindingTest.class.getResource("a.zip")))); CredentialsProvider.lookupStores(j.jenkins).iterator().next().addCredentials(Domain.global(), fc); final String contents = "Test of ZipFileBinding\n"; WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("" + "node {\n" + " withCredentials([[$class: 'ZipFileBinding', credentialsId: '"+ credentialsId +"', variable: 'ziploc']]) {\n" + " echo readFile(encoding: 'UTF-8', file: \"${env.ziploc}/dir/testfile.txt\")\n" + " }\n" + "}\n" , true)); WorkflowRun run = p.scheduleBuild2(0).get(); j.assertBuildStatusSuccess(run); j.assertLogContains(contents, run); }
Example #7
Source File: DefaultsBinderTest.java From pipeline-multibranch-defaults-plugin with MIT License | 6 votes |
@Test public void testDefaultJenkinsFile() throws Exception { GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class); ConfigFileStore store = globalConfigFiles.get(); Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "", "semaphore 'wait'; node {checkout scm; echo readFile('file')}"); store.save(config); sampleGitRepo.init(); sampleGitRepo.write("file", "initial content"); sampleGitRepo.git("commit", "--all", "--message=flow"); WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p"); mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0]))); WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master"); SemaphoreStep.waitForStart("wait/1", null); WorkflowRun b1 = p.getLastBuild(); assertNotNull(b1); assertEquals(1, b1.getNumber()); SemaphoreStep.success("wait/1", null); r.assertLogContains("initial content", r.waitForCompletion(b1)); }
Example #8
Source File: LockStepTest.java From lockable-resources-plugin with MIT License | 6 votes |
@Test public void lockWithLabel() throws Exception { LockableResourcesManager.get().createResourceWithLabel("resource1", "label1"); WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition( new CpsFlowDefinition( "lock(label: 'label1', variable: 'var') {\n" + " echo \"Resource locked: ${env.var}\"\n" + "}\n" + "echo 'Finish'", true)); WorkflowRun b1 = p.scheduleBuild2(0).waitForStart(); j.waitForCompletion(b1); j.assertBuildStatus(Result.SUCCESS, b1); j.assertLogContains("Lock released on resource [Label: label1]", b1); j.assertLogContains("Resource locked: resource1", b1); isPaused(b1, 1, 0); assertNotNull(LockableResourcesManager.get().fromName("resource1")); }
Example #9
Source File: VaultConfigurationIT.java From hashicorp-vault-plugin with MIT License | 6 votes |
@Test public void shouldUseJenkinsfileConfiguration() throws Exception { WorkflowJob pipeline = jenkins.createProject(WorkflowJob.class, "Pipeline"); pipeline.setDefinition(new CpsFlowDefinition("node {\n" + " wrap([$class: 'VaultBuildWrapperWithMockAccessor', \n" + " configuration: [$class: 'VaultConfiguration', \n" + " vaultCredentialId: '" + GLOBAL_CREDENTIALS_ID_2 + "', \n" + " vaultUrl: '" + JENKINSFILE_URL + "'], \n" + " vaultSecrets: [\n" + " [$class: 'VaultSecret', path: 'secret/path1', secretValues: [\n" + " [$class: 'VaultSecretValue', envVar: 'envVar1', vaultKey: 'key1']]]]]) {\n" + " " + getShellString() + " \"echo ${env.envVar1}\"\n" + " }\n" + "}", true)); WorkflowRun build = pipeline.scheduleBuild2(0).get(); jenkins.assertBuildStatus(Result.SUCCESS, build); jenkins.assertLogContains("echo ****", build); jenkins.assertLogNotContains("some-secret", build); }
Example #10
Source File: ChangeLogExtractorTest.java From atlassian-jira-software-cloud-plugin with Apache License 2.0 | 6 votes |
private WorkflowRun workflowRunWithIssuesAboveLimit() { int count = 105; Object[] changeSetEntries = new Object[count]; for (int i = 0; i < count; i++) { final ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class); when(entry.getMsg()).thenReturn(String.format("TEST-%d Commit message for %d", i, i)); changeSetEntries[i] = entry; } final ChangeLogSet changeLogSet = mock(ChangeLogSet.class); when(changeLogSet.getItems()).thenReturn(changeSetEntries); final WorkflowRun workflowRun = mock(WorkflowRun.class); when(workflowRun.getChangeSets()).thenReturn(ImmutableList.of(changeLogSet)); return workflowRun; }
Example #11
Source File: BindingStepTest.java From credentials-binding-plugin with MIT License | 6 votes |
@Test public void incorrectType() throws Exception { story.addStep(new Statement() { @Override public void evaluate() throws Throwable { StringCredentialsImpl c = new StringCredentialsImpl(CredentialsScope.GLOBAL, "creds", "sample", Secret.fromString("s3cr3t")); CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), c); WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("" + "node {\n" + " withCredentials([usernamePassword(usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD', credentialsId: 'creds')]) {\n" + " }\n" + "}", true)); WorkflowRun r = story.j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get()); // make sure error message contains information about the actual type and the expected type story.j.assertLogNotContains("s3cr3t", r); story.j.assertLogContains(StandardUsernamePasswordCredentials.class.getName(), r); // no descriptor for the interface type story.j.assertLogContains(stringCredentialsDescriptor.getDisplayName(), r); story.j.assertLogNotContains("\tat ", r); } }); }
Example #12
Source File: FindFilesStepTest.java From pipeline-utility-steps-plugin with MIT License | 6 votes |
@Test public void listSomeWithExclusions() throws Exception { String flow = CODE.replace("%TESTCODE%", "def files = findFiles(glob: '**/*.txt', excludes: 'b/*.txt,**/aba/*.txt')\n" + "echo \"${files.length} files\"\n" + "for(int i = 0; i < files.length; i++) {\n" + " echo \"F: ${files[i].path.replace('\\\\', '/')}\"\n" + "}" ); p.setDefinition(new CpsFlowDefinition(flow, true)); WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); j.assertLogContains("8 files", run); j.assertLogContains("F: 1.txt", run); j.assertLogContains("F: 2.txt", run); j.assertLogContains("F: a/3.txt", run); j.assertLogContains("F: a/4.txt", run); j.assertLogContains("F: a/aa/5.txt", run); j.assertLogContains("F: a/aa/6.txt", run); j.assertLogContains("F: a/ab/7.txt", run); j.assertLogContains("F: a/ab/8.txt", run); j.assertLogNotContains("F: a/ab/aba/9.txt", run); j.assertLogNotContains("F: a/ab/aba/10.txt", run); j.assertLogNotContains("F: b/11.txt", run); j.assertLogNotContains("F: b/12.txt", run); }
Example #13
Source File: VaultStringCredentialIT.java From hashicorp-vault-plugin with MIT License | 6 votes |
@Test public void shouldFailIfMissingCredentials() throws Exception { final String credentialsId = "cid1"; VaultStringCredentialImpl c = new VaultStringCredentialImpl( null, credentialsId, "Test Credentials"); c.setEngineVersion(1); CredentialsProvider.lookupStores(jenkins).iterator().next() .addCredentials(Domain.global(), c); WorkflowJob p = jenkins.createProject(WorkflowJob.class, "testJob"); p.setDefinition(new CpsFlowDefinition("" + "node {\n" + " withCredentials([[$class: 'VaultStringCredentialBinding', credentialsId: '" + credentialsId + "', variable: 'SECRET']]) { " + " " + getShellString() + " 'echo " + getVariable("SECRET") + "'\n" + " }\n" + "}", true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); jenkins.assertBuildStatus(Result.FAILURE, jenkins.waitForCompletion(b)); jenkins.assertLogContains("Exception", b); }
Example #14
Source File: GerritReviewStepTest.java From gerrit-code-review-plugin with Apache License 2.0 | 6 votes |
@Test public void gerritCommentStepInvokeNoAPITest() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition( new CpsFlowDefinition( "node {\n" + " withEnv([\n" + " ]) {\n" + " gerritReview label: 'Verified', score: -1, message: 'Does not work'\n" + " }\n" + "}", true)); WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); String log = JenkinsRule.getLog(run); j.assertLogContains("Gerrit Review is disabled no API URL", run); }
Example #15
Source File: BindingStepTest.java From credentials-binding-plugin with MIT License | 6 votes |
@Issue("JENKINS-42999") @Test public void widerRequiredContext() throws Exception { final String credentialsId = "creds"; final String credsFile = "credsFile"; final String credsContent = "s3cr3t"; story.addStep(new Statement() { @Override public void evaluate() throws Throwable { FileCredentialsImpl c = new FileCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "sample", credsFile, SecretBytes.fromBytes(credsContent.getBytes())); CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), c); WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("" + "withCredentials([file(variable: 'targetFile', credentialsId: '" + credentialsId + "')]) {\n" + " echo 'We should fail before getting here'\n" + "}", true)); WorkflowRun b = story.j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0)); story.j.assertLogNotContains("We should fail before getting here", b); story.j.assertLogContains("Required context class hudson.FilePath is missing", b); story.j.assertLogContains("Perhaps you forgot to surround the code with a step that provides this, such as: node", b); } }); }
Example #16
Source File: GraphBuilderTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void sequentialParallel() throws Exception { WorkflowRun run = createAndRunJob("sequentialParallel", "sequentialParallel.jenkinsfile"); NodeGraphBuilder graph = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run); List<FlowNodeWrapper> nodes = graph.getPipelineNodes(); assertStageAndEdges(nodes, "first-solo", "parent"); assertStageAndEdges(nodes, "parent", "multiple-stages", "other-single-stage", "single-stage"); assertStageAndEdges(nodes, "multiple-stages", "first-sequential-stage"); assertStageAndEdges(nodes, "other-single-stage", "second-solo"); assertStageAndEdges(nodes, "single-stage", "second-solo"); assertStageAndEdges(nodes, "second-solo"); assertStageAndEdges(nodes, "first-sequential-stage", "second-sequential-stage"); assertStageAndEdges(nodes, "second-sequential-stage", "third-sequential-stage"); assertStageAndEdges(nodes, "third-sequential-stage", "second-solo"); assertEquals("Unexpected stages in graph", 9, nodes.size()); }
Example #17
Source File: SimpleTravisRunnerDSLTest.java From simple-travis-runner-plugin with MIT License | 6 votes |
@Test public void timeoutStep() throws Exception { sampleRepo.init(); sampleRepo.write("somefile", ""); sampleRepo.write(".travis.yml", "script: sleep 75"); sampleRepo.write("Jenkinsfile", "simpleTravisRunner('.travis.yml', null, 1)"); sampleRepo.git("add", "Jenkinsfile"); sampleRepo.git("add", "somefile", ".travis.yml"); sampleRepo.git("commit", "--message=files"); story.addStep(new Statement() { @Override public void evaluate() throws Throwable { WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsScmFlowDefinition(new GitStep(sampleRepo.toString()).createSCM(), "Jenkinsfile")); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); story.j.assertLogNotContains("Travis Install", story.j.assertBuildStatus(Result.FAILURE, story.j.waitForCompletion(b))); story.j.assertLogContains("Travis Script", b); story.j.assertLogContains("Enforce time limit : Start", b); story.j.assertLogContains("Enforce time limit : End", b); story.j.assertLogContains("Sending interrupt signal to process", b); } }); }
Example #18
Source File: UnZipStepTest.java From pipeline-utility-steps-plugin with MIT License | 6 votes |
@Test public void unzipQuietReading() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition( "node('slaves') {\n" + " dir('zipIt') {\n" + " writeFile file: 'hello.txt', text: 'Hello World!'\n" + " writeFile file: 'hello.dat', text: 'Hello World!'\n" + " zip zipFile: '../hello.zip'\n" + " }\n" + " dir('unzip') {\n" + " def txt = unzip zipFile: '../hello.zip', quiet: true, read: true\n" + " echo \"Text: ${txt.values().join('\\n')}\"\n" + " }\n" + "}", true)); WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); j.assertLogNotContains("Reading: hello.txt", run); j.assertLogNotContains("Reading: hello.dat", run); j.assertLogContains("Read: 2 files", run); j.assertLogContains("Text: Hello World!", run); }
Example #19
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void stageTestJENKINS_40135() throws Exception { String script = "node {\n" + " stage 'Stage 1'\n" + " stage 'Stage 2'\n" + " echo 'hello'\n" + "}"; WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1"); job1.setDefinition(new CpsFlowDefinition(script, false)); WorkflowRun b1 = job1.scheduleBuild2(0).get(); j.assertBuildStatusSuccess(b1); List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class); Assert.assertEquals(2, nodes.size()); Assert.assertEquals("SUCCESS", nodes.get(0).get("result")); Assert.assertEquals("FINISHED", nodes.get(0).get("state")); Assert.assertEquals("SUCCESS", nodes.get(1).get("result")); Assert.assertEquals("FINISHED", nodes.get(1).get("state")); }
Example #20
Source File: S3PresignUrlStepTests.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Test public void presignWithExpiration() throws Exception { WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "s3PresignTest"); job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " def url = s3PresignURL(bucket: 'foo', key: 'bar', durationInSeconds: 10000)\n" + " echo \"url=$url\"\n" + "}\n", true) ); String urlString = "http://localhost:283/sdkd"; URL url = new URL(urlString); Mockito.when(this.s3.generatePresignedUrl(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(url); //minus a buffer for the test Date expectedDate = DateTime.now().plusSeconds(10000).minusSeconds(25).toDate(); WorkflowRun run = this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0)); jenkinsRule.assertLogContains("url=" + urlString, run); ArgumentCaptor<Date> expirationCaptor = ArgumentCaptor.forClass(Date.class); Mockito.verify(s3).generatePresignedUrl(Mockito.eq("foo"), Mockito.eq("bar"), expirationCaptor.capture(), Mockito.eq(HttpMethod.GET)); Assertions.assertThat(expirationCaptor.getValue()).isAfterOrEqualsTo(expectedDate); }
Example #21
Source File: WithContainerStepTest.java From docker-workflow-plugin with MIT License | 6 votes |
@Test public void stop() { story.addStep(new Statement() { @Override public void evaluate() throws Throwable { DockerTestUtil.assumeDocker(); WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj"); p.setDefinition(new CpsFlowDefinition( "node {\n" + " withDockerContainer('httpd:2.4.12') {\n" + " sh 'trap \\'echo got SIGTERM\\' TERM; trap \\'echo exiting; exit 99\\' EXIT; echo sleeping now with JENKINS_SERVER_COOKIE=$JENKINS_SERVER_COOKIE; sleep 999'\n" + " }\n" + "}", true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); story.j.waitForMessage("sleeping now", b); b.doStop(); story.j.assertBuildStatus(Result.ABORTED, story.j.waitForCompletion(b)); story.j.assertLogContains("script returned exit code 99", b); } }); }
Example #22
Source File: DatabaseSyncRunListener.java From pipeline-maven-plugin with MIT License | 6 votes |
@Override public void onCompleted(WorkflowRun workflowRun, @Nonnull TaskListener listener) { super.onCompleted(workflowRun, listener); // Note: run.duration is zero in onCompleted(), do the substraction in this listener Result result = workflowRun.getResult(); if (result == null) { result = Result.SUCCESS; // FIXME more elegant handling } globalPipelineMavenConfig.getDao().updateBuildOnCompletion( workflowRun.getParent().getFullName(), workflowRun.getNumber(), result.ordinal, workflowRun.getStartTimeInMillis(), Math.max(System.currentTimeMillis() - workflowRun.getStartTimeInMillis(), 0)); // @see HUDSON-5844 }
Example #23
Source File: ZipStepTest.java From pipeline-utility-steps-plugin with MIT License | 6 votes |
private void verifyArchivedHello(WorkflowRun run, String basePath) throws IOException { assertTrue("Build should have artifacts", run.getHasArtifacts()); Run<WorkflowJob, WorkflowRun>.Artifact artifact = run.getArtifacts().get(0); assertEquals("hello.zip", artifact.getFileName()); VirtualFile file = run.getArtifactManager().root().child(artifact.relativePath); try (ZipInputStream zip = new ZipInputStream(file.open())) { ZipEntry entry = zip.getNextEntry(); while (entry.isDirectory()) { entry = zip.getNextEntry(); } assertNotNull(entry); assertEquals(basePath + "hello.txt", entry.getName()); try (Scanner scanner = new Scanner(zip)) { assertTrue(scanner.hasNextLine()); assertEquals("Hello World!", scanner.nextLine()); assertNull("There should be no more entries", zip.getNextEntry()); } } }
Example #24
Source File: FindFilesStepTest.java From pipeline-utility-steps-plugin with MIT License | 6 votes |
@Test public void listSome() throws Exception { String flow = CODE.replace("%TESTCODE%", "def files = findFiles(glob: '**/a/*.txt')\n" + "echo \"${files.length} files\"\n" + "for(int i = 0; i < files.length; i++) {\n" + " echo \"F: ${files[i].path.replace('\\\\', '/')}\"\n" + "}" ); p.setDefinition(new CpsFlowDefinition(flow, true)); WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); j.assertLogContains("2 files", run); j.assertLogContains("F: a/3.txt", run); j.assertLogContains("F: a/4.txt", run); j.assertLogNotContains("F: 1.txt", run); j.assertLogNotContains("F: 2.txt", run); j.assertLogNotContains("F: a/aa/5.txt", run); j.assertLogNotContains("F: a/aa/6.txt", run); j.assertLogNotContains("F: a/ab/7.txt", run); j.assertLogNotContains("F: a/ab/8.txt", run); j.assertLogNotContains("F: a/ab/aba/9.txt", run); j.assertLogNotContains("F: a/ab/aba/10.txt", run); j.assertLogNotContains("F: b/11.txt", run); j.assertLogNotContains("F: b/12.txt", run); }
Example #25
Source File: DockerNodeStepTest.java From docker-plugin with MIT License | 6 votes |
@Test public void dockerBuilderPublisher() throws Exception { story.addStep(new Statement() { @Override public void evaluate() throws Throwable { try { runTest(); } finally { doCleanUp(); } } private void runTest() throws Throwable { WorkflowJob j = story.j.jenkins.createProject(WorkflowJob.class, "dockerBuilderPublisher"); j.setDefinition(new CpsFlowDefinition(dockerNodeJenkinsAgent() + " {\n" + " writeFile(file: 'Dockerfile', text: 'FROM jenkins/slave')\n" + " step([$class: 'DockerBuilderPublisher', dockerFileDirectory: ''])\n" + "}\n", true)); WorkflowRun r = story.j.buildAndAssertSuccess(j); story.j.assertLogContains("Successfully built", r); } }); }
Example #26
Source File: DownstreamPipelineTriggerRunListenerTest.java From pipeline-maven-plugin with MIT License | 5 votes |
protected void dumpBuildDetails(WorkflowRun build) { System.out.println(); System.out.println("# BUILD: " + build.getFullDisplayName()); System.out.println("## Dependencies"); List<MavenDependency> mavenDependencies = GlobalPipelineMavenConfig.get().getDao().listDependencies(build.getParent().getFullName(), build.number); for(MavenDependency mavenDependency: mavenDependencies) { System.out.println(mavenDependency); } System.out.println("## Generated Artifacts"); List<MavenArtifact> generatedArtifacts = GlobalPipelineMavenConfig.get().getDao().getGeneratedArtifacts(build.getParent().getFullName(), build.number); for(MavenArtifact generatedArtifact: generatedArtifacts) { System.out.println(generatedArtifact); } }
Example #27
Source File: ChangeLogExtractorTest.java From atlassian-jira-software-cloud-plugin with Apache License 2.0 | 5 votes |
@Test public void testExtractIssueKeys_forSquashedCommits() { // given final WorkflowRun workflowRun = changeSetWithSquashedCommitsInComment(); // when final Set<String> issueKeys = changeLogExtractor.extractIssueKeys(workflowRun); // then assertThat(issueKeys).containsExactlyInAnyOrder("TEST-3", "TEST-4"); }
Example #28
Source File: LockStepTest.java From lockable-resources-plugin with MIT License | 5 votes |
@Issue("JENKINS-40879") @Test public void parallelLockRelease() throws Exception { LockableResourcesManager.get().createResource("resource1"); LockableResourcesManager.get().createResource("resource2"); WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "j"); job.setDefinition( new CpsFlowDefinition( "lock(resource: 'resource1') {\n" + " semaphore 'wait-inside-1'\n" + "}\n" + "lock(resource: 'resource2') { \n" + " echo 'Entering semaphore now'\n" + " semaphore 'wait-inside-2'\n" + "}\n", true)); List<WorkflowRun> nextRuns = new ArrayList<>(); WorkflowRun toUnlock = null; for (int i = 0; i < 5; i++) { WorkflowRun rNext = job.scheduleBuild2(0).waitForStart(); if (toUnlock != null) { j.waitForMessage( "[resource1] is locked by " + toUnlock.getFullDisplayName() + ", waiting...", rNext); isPaused(rNext, 1, 1); SemaphoreStep.success("wait-inside-1/" + i, null); } SemaphoreStep.waitForStart("wait-inside-1/" + (i + 1), rNext); isPaused(rNext, 1, 0); nextRuns.add(rNext); toUnlock = rNext; } SemaphoreStep.success("wait-inside-1/" + nextRuns.size(), null); waitAndClear(1, nextRuns); }
Example #29
Source File: ReadCSVStepTest.java From pipeline-utility-steps-plugin with MIT License | 5 votes |
@Test public void readNone() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition( "node {\n" + " List<CSVRecord> records = readCSV()\n" + "}", true)); WorkflowRun run = p.scheduleBuild2(0).get(); j.assertBuildStatus(Result.FAILURE, run); j.assertLogContains(AbstractFileOrTextStepDescriptorImpl_missingRequiredArgument("readCSV"), run); }
Example #30
Source File: PipelineNodeImpl.java From blueocean-plugin with MIT License | 5 votes |
public PipelineNodeImpl(FlowNodeWrapper node, Reachable parent, WorkflowRun run) { this.node = node; this.run = run; this.edges = buildEdges(node.edges); this.status = node.getStatus(); this.durationInMillis = node.getTiming().getTotalDurationMillis(); this.self = parent.getLink().rel(node.getId()); this.parent = parent; }