Refine search
private FreeStyleBuild getBuild() throws ExecutionException, InterruptedException { return project.scheduleBuild2(0).get(); } }
@Test public void testNoParametersBuild() throws Exception { addBuildStep(); FreeStyleBuild build = p.scheduleBuild2(0).get(); Result result = build.getResult(); assertSuccessfulBuild(result); }
/** * Trying to run a step without having the required context should result in a graceful error. */ @Test public void missingContextCheck() throws Exception { p.setDefinition(new CpsFlowDefinition("readFile 'true'", true)); WorkflowRun b = p.scheduleBuild2(0).get(); jenkins.assertLogContains("such as: node", b); // make sure the 'node' is a suggested message. this comes from MissingContextVariableException // jenkins.assertLogNotContains("Exception", b) // haven't figured out how to hide this jenkins.assertBuildStatus(Result.FAILURE, b); }
@Test public void testNoParameterBuild() throws Exception { addBuildStep(); FreeStyleBuild build = p.scheduleBuild2(0).get(); Result result = build.getResult(); assertSuccessfulBuild(result); }
/** * Not a syntax error but semantics error in using the 'pipeline' step. * This should be reported nicely. */ @Test public void errorInJenkinsfile() throws Exception { WorkflowJob job = j.createProject(WorkflowJob.class); // still a syntactically valid groovy code but no stage name job.setDefinition(new CpsFlowDefinition("pipeline { stages { stage { sh './test.sh' } } }")); WorkflowRun b = j.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); j.assertLogContains(Messages.ModelParser_ExpectedStringLiteral(), b); j.assertLogContains(String.format(" pipeline { stages { stage { sh './test.sh' } } }%n" + " ^%n") ,b); }
private FreeStyleBuild getBuild() throws ExecutionException, InterruptedException { return project.scheduleBuild2(0).get(); } }
@Test public void testBuildNoConduit() throws Exception { addBuildStep(); TestUtils.setDefaultBuildEnvironment(j); FreeStyleBuild build = p.scheduleBuild2(0).get(); assertFailureWithMessage("No credentials configured", build); }
@Issue("SECURITY-567") @Test public void methodPointers() throws Exception { logging.record(CpsTransformer.class, Level.FINEST); WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p"); job.setDefinition(new CpsFlowDefinition("println((Jenkins.&getInstance)())", true)); WorkflowRun b = job.scheduleBuild2(0).get(); jenkins.assertBuildStatus(Result.FAILURE, b); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance", b); }
protected FreeStyleBuild buildWithCommit(JSONObject sendMessageResponse) throws Exception { Map<String, JSONObject> responses = new HashMap<String, JSONObject>(); responses.put("harbormaster.sendmessage", sendMessageResponse); responses.put("harbormaster.createartifact", new JSONObject()); conduit = new FakeConduit(responses); TestUtils.addValidCredentials(conduit); addBuildStep(); TestUtils.setDefaultBuildEnvironmentForCommits(j); return p.scheduleBuild2(0).get(); }
@Test public void testNoCredentials() throws Exception { addBuildStep(); TestUtils.setDefaultBuildEnvironment(j); FreeStyleBuild build = p.scheduleBuild2(0).get(); assertFailureWithMessage("No credentials configured for conduit", build); }
@Issue("JENKINS-46088") @Test public void rhsOfDeclarationSandboxedInCPS() throws Exception { logging.record(CpsTransformer.class, Level.FINEST); WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p"); job.setDefinition(new CpsFlowDefinition("jenkins.model.Jenkins x = jenkins.model.Jenkins.getInstance()\n", true)); WorkflowRun b = job.scheduleBuild2(0).get(); jenkins.assertBuildStatus(Result.FAILURE, b); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance", b); }
/** * Creates a new freestyle project and checks if the rebuild action is * available on the project level. * * @throws Exception * Exception */ public void testWhenProjectWithoutParamsThenRebuildProjectAvailable() throws Exception { FreeStyleProject project = createFreeStyleProject(); FreeStyleBuild build = project.scheduleBuild2(0).get(); RebuildLastCompletedBuildAction action = build.getProject().getAction( RebuildLastCompletedBuildAction.class); assertNotNull(action); }
@LocalData("All") @Test public void persistence() throws Exception { project.scheduleBuild2(0).get(60, TimeUnit.SECONDS); reloadJenkins(); FreeStyleBuild build = project.getBuildByNumber(1); assertTestResults(build); }
@Test public void renameWhileComputing() throws Exception { CoordinatedComputedFolder d = r.jenkins.createProject(CoordinatedComputedFolder.class, "d"); d.kids.addAll(Arrays.asList("A", "B")); QueueTaskFuture<Queue.Executable> future = d.scheduleBuild2(0).getFuture(); future.waitForStart(); try { d.checkRename("d2"); fail("Should be blocked while computation is in progress"); } catch (Failure f) { assertThat(f.getMessage(), is(Messages.ComputedFolder_ComputationInProgress())); } d.onKid("B"); future.get(); waitUntilNoActivityIgnoringThreadDeathUpTo(10000); d.checkRename("d2"); }
protected FreeStyleBuild buildWithConduit( JSONObject queryDiffsResponse, JSONObject postCommentResponse, JSONObject sendMessageResponse, boolean harbormaster) throws Exception { Map<String, JSONObject> responses = new HashMap<String, JSONObject>(); if (queryDiffsResponse != null) { responses.put("differential.querydiffs", queryDiffsResponse); } if (postCommentResponse != null) { responses.put("differential.createcomment", postCommentResponse); } if (sendMessageResponse != null) { responses.put("harbormaster.sendmessage", sendMessageResponse); } responses.put("differential.getcommitmessage", new JSONObject().element("result", "commit message")); conduit = new FakeConduit(responses); TestUtils.addValidCredentials(conduit); addBuildStep(); TestUtils.setDefaultBuildEnvironment(j, harbormaster); return p.scheduleBuild2(0).get(); }
/** * Tests the "URL@HEAD" format in the SVN URL */ @Test public void headRevisionCheckout() throws Exception { File testRepo = new CopyExisting(getClass().getResource("two-revisions.zip")).allocate(); SubversionSCM scm = new SubversionSCM("file://" + testRepo.toURI().toURL().getPath() + "@HEAD"); FreeStyleProject p = r.createFreeStyleProject(); p.setScm(scm); FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserIdCause()).get(); System.out.println(b.getLog(LOG_LIMIT)); r.assertLogContains("At revision 2", b); r.assertBuildStatus(Result.SUCCESS,b); }
@Issue({"JENKINS-42563", "SECURITY-582"}) @Test public void superCallsSandboxed() throws Exception { logging.record(CpsTransformer.class, Level.FINEST); WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p"); job.setDefinition(new CpsFlowDefinition("class X extends groovy.json.JsonSlurper {def parse(url) {super.parse(new URL(url))}}; echo(/got ${new X().parse(\"${JENKINS_URL}api/json\")}/)", true)); WorkflowRun r = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.json.JsonSlurper parse java.net.URL", r); job.setDefinition(new CpsFlowDefinition("class X extends groovy.json.JsonSlurper {def m(url) {super.parse(new URL(url))}}; echo(/got ${new X().m(\"${JENKINS_URL}api/json\")}/)", true)); r = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.json.JsonSlurper parse java.net.URL", r); job.setDefinition(new CpsFlowDefinition("class X extends File {X(String f) {super(f)}}; echo(/got ${new X('x')}/)", true)); r = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.io.File java.lang.String", r); }
/** * Manufactures commits including metadata * @return */ private void createWorkingCopy(SubversionSCM scm) throws Exception { FreeStyleProject forCommit = r.createFreeStyleProject(); forCommit.setScm(scm); forCommit.setAssignedLabel(r.jenkins.getSelfLabel()); FreeStyleBuild b = r.assertBuildStatusSuccess(forCommit.scheduleBuild2(0).get()); workingcopy = b.getWorkspace(); }
@Test public void testBuildInvalidConduit() throws Exception { TestUtils.addInvalidCredentials(); addBuildStep(); TestUtils.setDefaultBuildEnvironment(j); FreeStyleBuild build = p.scheduleBuild2(0).get(); assertEquals(Result.FAILURE, build.getResult()); }
@Issue("JENKINS-46088") @Test public void rhsOfDeclarationTransformedInNonCPS() throws Exception { logging.record(CpsTransformer.class, Level.FINEST); WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p"); job.setDefinition(new CpsFlowDefinition("@NonCPS\n" + "def willFail() {\n" + " jenkins.model.Jenkins x = jenkins.model.Jenkins.getInstance()\n" + "}\n" + "willFail()\n", true)); WorkflowRun b = job.scheduleBuild2(0).get(); jenkins.assertBuildStatus(Result.FAILURE, b); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance", b); }