hudson.tasks.Shell Java Examples
The following examples show how to use
hudson.tasks.Shell.
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 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 #3
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 #4
Source File: FreestyleTest.java From yet-another-docker-plugin with MIT License | 6 votes |
@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; }
Example #5
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 #6
Source File: ShellScriptRunner.java From DotCi with MIT License | 6 votes |
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; }
Example #7
Source File: MarathonRecorderTest.java From marathon-plugin with Apache License 2.0 | 6 votes |
/** * 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()); }
Example #8
Source File: AlmquistShellSecretPatternFactoryTest.java From credentials-binding-plugin with MIT License | 6 votes |
@Before public void setUp() throws IOException { j.jenkins.getDescriptorByType(Shell.DescriptorImpl.class).setShell(Executables.getPathToExecutable("ash")); project = j.createProject(WorkflowJob.class); credentialsId = UUID.randomUUID().toString(); project.setDefinition(new CpsFlowDefinition( "node {\n" + " withCredentials([string(credentialsId: '" + credentialsId + "', variable: 'CREDENTIALS')]) {\n" + " sh '''\n" + " echo begin0 $CREDENTIALS end0\n" + // begin2 => 2 for double quotes " echo \"begin2 $CREDENTIALS end2\"\n" + " '''\n" + " }\n" + "}", true)); }
Example #9
Source File: ArtifactContainerImplTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void testArtifactsListing() throws Exception { FreeStyleProject p = j.createFreeStyleProject(JOB_NAME); p.getBuildersList().add(new Shell("#!/bin/bash\nmkdir -p test/me/out; cd test/me/out; touch {0..105}.txt")); p.getPublishersList().add(new ArtifactArchiver("**/*")); Run r = p.scheduleBuild2(0).waitForStart(); r = j.waitForCompletion(r); List artifacts = request().get("/organizations/jenkins/pipelines/"+JOB_NAME+"/runs/"+r.getId()+"/artifacts").build(List.class); Assert.assertEquals(100, artifacts.size()); Assert.assertEquals(0, ((Map) artifacts.get(0)).get("size")); Assert.assertEquals("test/me/out/0.txt", ((Map) artifacts.get(0)).get("path")); Assert.assertEquals("/job/artifactTest/1/artifact/test/me/out/0.txt", ((Map) artifacts.get(0)).get("url")); }
Example #10
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void actionsTest() throws Exception { FreeStyleProject p = j.createFreeStyleProject("pipeline1"); p.getBuildersList().add(new Shell("echo hello!\nsleep 1")); FreeStyleBuild b = p.scheduleBuild2(0).get(); j.assertBuildStatusSuccess(b); Map resp = get("/organizations/jenkins/pipelines/pipeline1/", Map.class); List<Map> actions = (List<Map>) resp.get("actions"); Assert.assertTrue(actions.isEmpty()); actions = (List<Map>) ((Map)resp.get("latestRun")).get("actions"); resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/", Map.class); actions = (List<Map>) resp.get("actions"); Assert.assertTrue(actions.isEmpty()); resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/?tree=*[*]", Map.class); actions = (List<Map>) resp.get("actions"); Assert.assertFalse(actions.isEmpty()); }
Example #11
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void parameterizedFreestyleTestWithoutDefaultParam() throws Exception { FreeStyleProject p = j.createFreeStyleProject("pp"); p.addProperty(new ParametersDefinitionProperty(new TestStringParameterDefinition("version", null, "version number"))); p.getBuildersList().add(new Shell("echo hello!")); Map resp = get("/organizations/jenkins/pipelines/pp/"); List<Map<String,Object>> parameters = (List<Map<String, Object>>) resp.get("parameters"); assertEquals(1, parameters.size()); assertEquals("version", parameters.get(0).get("name")); assertEquals("TestStringParameterDefinition", parameters.get(0).get("type")); assertEquals("version number", parameters.get(0).get("description")); assertNull(parameters.get(0).get("defaultParameterValue")); validatePipeline(p, resp); resp = post("/organizations/jenkins/pipelines/pp/runs/", ImmutableMap.of("parameters", ImmutableList.of() ), 400); }
Example #12
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void parameterizedFreestyleTest() throws Exception { FreeStyleProject p = j.createFreeStyleProject("pp"); p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("version", "1.0", "version number"))); p.getBuildersList().add(new Shell("echo hello!")); Map resp = get("/organizations/jenkins/pipelines/pp/"); List<Map<String,Object>> parameters = (List<Map<String, Object>>) resp.get("parameters"); assertEquals(1, parameters.size()); assertEquals("version", parameters.get(0).get("name")); assertEquals("StringParameterDefinition", parameters.get(0).get("type")); assertEquals("version number", parameters.get(0).get("description")); assertEquals("1.0", ((Map)parameters.get(0).get("defaultParameterValue")).get("value")); validatePipeline(p, resp); resp = post("/organizations/jenkins/pipelines/pp/runs/", ImmutableMap.of("parameters", ImmutableList.of(ImmutableMap.of("name", "version", "value", "2.0")) ), 200); assertEquals("pp", resp.get("pipeline")); Thread.sleep(1000); resp = get("/organizations/jenkins/pipelines/pp/runs/1/"); assertEquals("SUCCESS", resp.get("result")); assertEquals("FINISHED", resp.get("state")); }
Example #13
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void testPipelineQueue() throws Exception { FreeStyleProject p1 = j.createFreeStyleProject("pipeline1"); p1.setConcurrentBuild(true); p1.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("test","test"))); p1.getBuildersList().add(new Shell("echo hello!\nsleep 300")); p1.scheduleBuild2(0).waitForStart(); p1.scheduleBuild2(0).waitForStart(); Jenkins.getInstance().getQueue().schedule(p1, 0, new ParametersAction(new StringParameterValue("test","test1")), new CauseAction(new Cause.UserIdCause())); Jenkins.getInstance().getQueue().schedule(p1, 0, new ParametersAction(new StringParameterValue("test","test2")), new CauseAction(new Cause.UserIdCause())); List queue = request().get("/organizations/jenkins/pipelines/pipeline1/queue").build(List.class); Assert.assertEquals(2, queue.size()); Assert.assertEquals(4, ((Map) queue.get(0)).get("expectedBuildNumber")); Assert.assertEquals(3, ((Map) queue.get(1)).get("expectedBuildNumber")); Assert.assertEquals("Waiting for next available executor", ((Map) queue.get(0)).get("causeOfBlockage")); Assert.assertEquals("Waiting for next available executor", ((Map) queue.get(1)).get("causeOfBlockage")); Run r = QueueUtil.getRun(p1, Long.parseLong((String)((Map)queue.get(0)).get("id"))); assertNull(r); //its not moved out of queue yet }
Example #14
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void getPipelineRunsStopTest() throws Exception { FreeStyleProject p = j.createFreeStyleProject("p1"); p.getBuildersList().add(new Shell("sleep 600000")); FreeStyleBuild b = p.scheduleBuild2(0).waitForStart(); //wait till its running do{ Thread.sleep(10); //sleep for 10ms }while(b.hasntStartedYet()); Map resp = put("/organizations/jenkins/pipelines/p1/runs/"+b.getId()+"/stop/?blocking=true", Map.class); // we can't actually guarantee that jenkins will stop it assertTrue(resp.get("result").equals("ABORTED") || resp.get("result").equals("UNKNOWN")); }
Example #15
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 #16
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 #17
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 #18
Source File: JobsTest.java From jenkins-client-java with MIT License | 6 votes |
@Test public void getLogText() throws IOException, ExecutionException, InterruptedException { FreeStyleProject project = j.createFreeStyleProject(); FreeStyleBuild build = project.scheduleBuild2(0).waitForStart(); j.waitForCompletion(build); String log = jobs.getLogText(project.getName(), 1); assertNotNull(log); assertThat(log, containsString("Finished:")); project.getBuildersList().add(new Shell("echo hello")); build = project.scheduleBuild2(0).waitForStart(); j.waitForCompletion(build); log = jobs.getLogText(project.getName(), 2); assertThat(log, containsString("hello")); }
Example #19
Source File: BuildWrapperOrderCredentialsBindingTest.java From credentials-binding-plugin with MIT License | 6 votes |
@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); }
Example #20
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 #21
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 #22
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 #23
Source File: SecretBuildWrapperTest.java From credentials-binding-plugin with MIT License | 5 votes |
@Issue("JENKINS-24805") @Test public void emptySecretsList() throws Exception { SecretBuildWrapper wrapper = new SecretBuildWrapper(new ArrayList<MultiBinding<?>>()); FreeStyleProject f = r.createFreeStyleProject(); f.setConcurrentBuild(true); f.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo PASSES") : new Shell("echo PASSES")); f.getBuildWrappersList().add(wrapper); r.configRoundtrip((Item)f); FreeStyleBuild b = r.buildAndAssertSuccess(f); r.assertLogContains("PASSES", b); }
Example #24
Source File: BashSecretPatternFactoryTest.java From credentials-binding-plugin with MIT License | 5 votes |
@Before public void setUp() throws IOException { j.jenkins.getDescriptorByType(Shell.DescriptorImpl.class).setShell(Executables.getPathToExecutable("bash")); project = j.createProject(WorkflowJob.class); credentialsId = UUID.randomUUID().toString(); project.setDefinition(new CpsFlowDefinition( "node {\n" + " withCredentials([string(credentialsId: '" + credentialsId + "', variable: 'CREDENTIALS')]) {\n" + " sh ': \"$CREDENTIALS\"'\n" + // : will expand its parameters and do nothing with them " sh ': \"< $CREDENTIALS >\"'\n" + // surround credentials with identifiable text for partial quoting " }\n" + "}", true)); }
Example #25
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 #26
Source File: BashSecretPatternFactory2Test.java From credentials-binding-plugin with MIT License | 5 votes |
@Before public void setUp() { assumeThat("bash", is(executable())); // due to https://github.com/jenkinsci/durable-task-plugin/blob/e75123eda986f20a390d92cc892c3d206e60aefb/src/main/java/org/jenkinsci/plugins/durabletask/BourneShellScript.java#L149 // on Windows assumeThat("nohup", is(executable())); j.jenkins.getDescriptorByType(Shell.DescriptorImpl.class).setShell(Executables.getPathToExecutable("bash")); }
Example #27
Source File: WorkspaceFileExporterTest.java From DotCi with MIT License | 5 votes |
@Test public void should_delete_file_from_workspace_for_delete_operation() throws IOException, InterruptedException, ExecutionException { final WorkspaceFileExporter deleteFile = new WorkspaceFileExporter(new WorkspaceFileExporter.WorkspaceFile("test.txt"), WorkspaceFileExporter.Operation.DELETE); final FreeStyleProject project = this.jenkinsRule.createFreeStyleProject(); project.getBuildersList().add(new Shell("touch text.txt")); project.getBuildersList().add(deleteFile); final FreeStyleBuild build = project.scheduleBuild2(0).get(); final String output = FileUtils.readFileToString(build.getLogFile()); assertThat(output).doesNotContain("test.txt"); }
Example #28
Source File: WorkspaceFileExporterTest.java From DotCi with MIT License | 5 votes |
@Test public void should_export_file_into_workspace_for_create_operation() throws IOException, InterruptedException, ExecutionException { final WorkspaceFileExporter createFile = new WorkspaceFileExporter(new WorkspaceFileExporter.WorkspaceFile("test.txt", "test Content", "rw-r--r--"), WorkspaceFileExporter.Operation.CREATE); final FreeStyleProject project = this.jenkinsRule.createFreeStyleProject(); project.getBuildersList().add(createFile); project.getBuildersList().add(new Shell("ls -la")); project.getBuildersList().add(new Shell("cat test.txt")); final FreeStyleBuild build = project.scheduleBuild2(0).get(); final String output = FileUtils.readFileToString(build.getLogFile()); assertThat(output).contains("test.txt"); assertThat(output).contains("test Content"); }
Example #29
Source File: SecretBuildWrapperTest.java From credentials-binding-plugin with MIT License | 5 votes |
@Issue("JENKINS-41760") @Test public void emptySecret() throws Exception { CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), new StringCredentialsImpl(CredentialsScope.GLOBAL, "creds", null, Secret.fromString(""))); FreeStyleProject p = r.createFreeStyleProject(); p.getBuildWrappersList().add(new SecretBuildWrapper(Collections.singletonList(new StringBinding("SECRET", "creds")))); p.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo PASSES") : new Shell("echo PASSES")); r.assertLogContains("PASSES", r.buildAndAssertSuccess(p)); }
Example #30
Source File: SecretBuildWrapperTest.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 = "p4$$"; 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 = "p4$$" + "someMoreStuff"; 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 f = r.createFreeStyleProject(); f.setConcurrentBuild(true); f.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_1%") : new Shell("echo \"$PASS_1\"")); f.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_2%") : new Shell("echo \"$PASS_2\"")); f.getBuildWrappersList().add(wrapper); r.configRoundtrip((Item)f); FreeStyleBuild b = r.buildAndAssertSuccess(f); r.assertLogNotContains(firstPassword, b); r.assertLogNotContains(secondPassword, b); r.assertLogContains("****", b); }