Java Code Examples for hudson.model.FreeStyleProject#addProperty()
The following examples show how to use
hudson.model.FreeStyleProject#addProperty() .
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 | 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 2
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 3
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 4
Source File: GHBranchSubscriberTest.java From github-integration-plugin with MIT License | 6 votes |
@Test public void dontFailOnBadJob() throws IOException, ANTLRException { String goodRepo = "https://github.com/KostyaSha-auto/test-repo"; final FreeStyleProject job1 = jRule.createProject(FreeStyleProject.class, "bad job"); job1.addProperty(new GithubProjectProperty("http://bad.url/deep/bad/path/")); job1.addTrigger(new GitHubBranchTrigger("", GitHubPRTriggerMode.HEAVY_HOOKS_CRON, emptyList())); Set<Job> jobs = getBranchTriggerJobs(goodRepo); assertThat(jobs, hasSize(0)); final FreeStyleProject job2 = jRule.createProject(FreeStyleProject.class, "good job"); job2.addProperty(new GithubProjectProperty(goodRepo)); job2.addTrigger(new GitHubBranchTrigger("", GitHubPRTriggerMode.HEAVY_HOOKS_CRON, emptyList())); jobs = getBranchTriggerJobs("KostyaSha-auto/test-repo"); assertThat(jobs, hasSize(1)); assertThat(jobs, hasItems(job2)); }
Example 5
Source File: FreeStyleProjectTest.java From lockable-resources-plugin with MIT License | 6 votes |
@Test public void configRoundTripPlain() throws Exception { LockableResourcesManager.get().createResource("resource1"); FreeStyleProject withResource = j.createFreeStyleProject("withResource"); withResource.addProperty( new RequiredResourcesProperty("resource1", "resourceNameVar", null, null, null)); FreeStyleProject withResourceRoundTrip = j.configRoundtrip(withResource); RequiredResourcesProperty withResourceProp = withResourceRoundTrip.getProperty(RequiredResourcesProperty.class); assertNotNull(withResourceProp); assertEquals("resource1", withResourceProp.getResourceNames()); assertEquals("resourceNameVar", withResourceProp.getResourceNamesVar()); assertNull(withResourceProp.getResourceNumber()); assertNull(withResourceProp.getLabelName()); assertNull(withResourceProp.getResourceMatchScript()); }
Example 6
Source File: GHPullRequestSubscriberTest.java From github-integration-plugin with MIT License | 6 votes |
@Test public void shouldTriggerJobOnPullRequestOpen() throws Exception { when(trigger.getRepoFullName(any(AbstractProject.class))).thenReturn(create(REPO_URL_FROM_PAYLOAD)); when(trigger.getTriggerMode()).thenReturn(GitHubPRTriggerMode.HEAVY_HOOKS); FreeStyleProject job = jenkins.createFreeStyleProject(); job.addProperty(new GithubProjectProperty(REPO_URL_FROM_PAYLOAD)); job.addTrigger(trigger); new GHPullRequestSubscriber().onEvent(new GHSubscriberEvent( "", GHEvent.PULL_REQUEST, classpath("payload/pull_request.json")) ); verify(trigger).queueRun(eq(job), eq(1)); }
Example 7
Source File: GHPullRequestSubscriberTest.java From github-integration-plugin with MIT License | 6 votes |
@Test public void dontFailOnBadJob() throws IOException, ANTLRException { String goodRepo = "https://github.com/KostyaSha-auto/test-repo"; final FreeStyleProject job1 = jenkins.createProject(FreeStyleProject.class, "bad job"); job1.addProperty(new GithubProjectProperty("http://bad.url/deep/bad/path/")); job1.addTrigger(new GitHubPRTrigger("", GitHubPRTriggerMode.HEAVY_HOOKS_CRON, emptyList())); Set<Job> jobs = getPRTriggerJobs(goodRepo); MatcherAssert.assertThat(jobs, hasSize(0)); final FreeStyleProject job2 = jenkins.createProject(FreeStyleProject.class, "good job"); job2.addProperty(new GithubProjectProperty(goodRepo)); job2.addTrigger(new GitHubPRTrigger("", GitHubPRTriggerMode.HEAVY_HOOKS_CRON, emptyList())); jobs = getPRTriggerJobs("KostyaSha-auto/test-repo"); MatcherAssert.assertThat(jobs, hasSize(1)); MatcherAssert.assertThat(jobs, hasItems(job2)); }
Example 8
Source File: SaveableChangeListenerTest.java From audit-log-plugin with MIT License | 6 votes |
@Issue("ISSUE-35") @Test public void testOnCredentialsUsage() throws Exception { UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "secret-id", "test credentials", "bob","secret"); CredentialsProvider.lookupStores(j.jenkins).iterator().next().addCredentials(Domain.global(), credentials); JenkinsRule.WebClient wc = j.createWebClient(); FreeStyleProject job = j.createFreeStyleProject(); job.addProperty(new ParametersDefinitionProperty( new CredentialsParameterDefinition( "SECRET", "The secret", "secret-id", Credentials.class.getName(), false ))); job.getBuildersList().add(new CaptureEnvironmentBuilder()); job.scheduleBuild2(0, new ParametersAction(new CredentialsParameterValue("SECRET", "secret-id", "The secret", true))).get(); List<LogEvent> events = app.getEvents(); assertThat(events).hasSize(4); assertThat(events).extracting(event -> ((AuditMessage) event.getMessage()).getId().toString()).containsSequence("createItem", "buildStart", "useCredentials", "buildFinish"); }
Example 9
Source File: InteroperabilityTest.java From lockable-resources-plugin with MIT License | 5 votes |
@Test public void interoperability() throws Exception { final Semaphore semaphore = new Semaphore(1); LockableResourcesManager.get().createResource("resource1"); WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition( new CpsFlowDefinition( "lock('resource1') {\n" + " echo 'Locked'\n" + "}\n" + "echo 'Finish'", true)); FreeStyleProject f = j.createFreeStyleProject("f"); f.addProperty(new RequiredResourcesProperty("resource1", null, null, null, null)); f.getBuildersList() .add( new TestBuilder() { @Override public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { semaphore.acquire(); return true; } }); semaphore.acquire(); FreeStyleBuild f1 = f.scheduleBuild2(0).waitForStart(); WorkflowRun b1 = p.scheduleBuild2(0).waitForStart(); j.waitForMessage("[resource1] is locked by " + f1.getFullDisplayName() + ", waiting...", b1); isPaused(b1, 1, 1); semaphore.release(); // Wait for lock after the freestyle finishes j.waitForMessage("Lock released on resource [resource1]", b1); isPaused(b1, 1, 0); }
Example 10
Source File: PendingBuildsHandlerTest.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private Project freestyleProject(String name, GitLabCommitStatusPublisher gitLabCommitStatusPublisher) throws IOException { FreeStyleProject project = jenkins.createFreeStyleProject(name); project.setQuietPeriod(5000); project.getPublishersList().add(gitLabCommitStatusPublisher); project.addProperty(gitLabConnectionProperty); return project; }
Example 11
Source File: FreeStyleProjectTest.java From lockable-resources-plugin with MIT License | 5 votes |
@Test public void configRoundTripWithLabel() throws Exception { FreeStyleProject withLabel = j.createFreeStyleProject("withLabel"); withLabel.addProperty(new RequiredResourcesProperty(null, null, null, "some-label", null)); FreeStyleProject withLabelRoundTrip = j.configRoundtrip(withLabel); RequiredResourcesProperty withLabelProp = withLabelRoundTrip.getProperty(RequiredResourcesProperty.class); assertNotNull(withLabelProp); assertNull(withLabelProp.getResourceNames()); assertNull(withLabelProp.getResourceNamesVar()); assertNull(withLabelProp.getResourceNumber()); assertEquals("some-label", withLabelProp.getLabelName()); assertNull(withLabelProp.getResourceMatchScript()); }
Example 12
Source File: GitHubPRTriggerTest.java From github-integration-plugin with MIT License | 5 votes |
@Test public void shouldParseRepoNameFromProp() throws IOException, ANTLRException { FreeStyleProject p = j.createFreeStyleProject(); String org = "org"; String repo = "repo"; p.addProperty(new GithubProjectProperty(format("https://github.com/%s/%s", org, repo))); GitHubRepositoryName fullName = defaultGitHubPRTrigger().getRepoFullName(p); assertThat(fullName.getUserName(), equalTo(org)); assertThat(fullName.getRepositoryName(), equalTo(repo)); }
Example 13
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 14
Source File: FreeStyleProjectTest.java From lockable-resources-plugin with MIT License | 5 votes |
@Test public void autoCreateResource() throws IOException, InterruptedException, ExecutionException { FreeStyleProject f = j.createFreeStyleProject("f"); f.addProperty(new RequiredResourcesProperty("resource1", null, null, null, null)); FreeStyleBuild fb1 = f.scheduleBuild2(0).waitForStart(); j.waitForMessage("acquired lock on [resource1]", fb1); j.waitForCompletion(fb1); assertNull(LockableResourcesManager.get().fromName("resource1")); }
Example 15
Source File: FreeStyleProjectTest.java From lockable-resources-plugin with MIT License | 4 votes |
@Test public void approvalRequired() throws Exception { LockableResourcesManager.get().createResource(LockableResourcesRootAction.ICON); j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); j.jenkins.setAuthorizationStrategy( new MockAuthorizationStrategy() .grant(Jenkins.READ, Item.READ) .everywhere() .toAuthenticated() .grant(Jenkins.ADMINISTER) .everywhere() .to("bob") .grant(Item.CONFIGURE, Item.BUILD) .everywhere() .to("alice")); final String SCRIPT = "resourceName == org.jenkins.plugins.lockableresources.actions.LockableResourcesRootAction.ICON;"; FreeStyleProject p = j.createFreeStyleProject(); SecureGroovyScript groovyScript = new SecureGroovyScript(SCRIPT, true, null).configuring(ApprovalContext.create()); p.addProperty(new RequiredResourcesProperty(null, null, null, null, groovyScript)); User.getOrCreateByIdOrFullName("alice"); JenkinsRule.WebClient wc = j.createWebClient(); wc.login("alice"); QueueTaskFuture<FreeStyleBuild> futureBuild = p.scheduleBuild2(0); TestHelpers.waitForQueue(j.jenkins, p, Queue.BlockedItem.class); Queue.BlockedItem blockedItem = (Queue.BlockedItem) j.jenkins.getQueue().getItem(p); assertThat( blockedItem.getCauseOfBlockage(), is(instanceOf(LockableResourcesQueueTaskDispatcher.BecauseResourcesQueueFailed.class))); ScriptApproval approval = ScriptApproval.get(); List<ScriptApproval.PendingSignature> pending = new ArrayList<>(); pending.addAll(approval.getPendingSignatures()); assertFalse(pending.isEmpty()); assertEquals(1, pending.size()); ScriptApproval.PendingSignature firstPending = pending.get(0); assertEquals( "staticField org.jenkins.plugins.lockableresources.actions.LockableResourcesRootAction ICON", firstPending.signature); approval.approveSignature(firstPending.signature); j.assertBuildStatusSuccess(futureBuild); }
Example 16
Source File: FreeStyleProjectTest.java From lockable-resources-plugin with MIT License | 4 votes |
@Test public void migrateToScript() throws Exception { LockableResourcesManager.get().createResource("resource1"); FreeStyleProject p = j.createFreeStyleProject("p"); p.addProperty( new RequiredResourcesProperty( null, null, null, "groovy:resourceName == 'resource1'", null)); p.save(); j.jenkins.reload(); FreeStyleProject p2 = j.jenkins.getItemByFullName("p", FreeStyleProject.class); RequiredResourcesProperty newProp = p2.getProperty(RequiredResourcesProperty.class); assertNull(newProp.getLabelName()); assertNotNull(newProp.getResourceMatchScript()); assertEquals("resourceName == 'resource1'", newProp.getResourceMatchScript().getScript()); SemaphoreBuilder p2Builder = new SemaphoreBuilder(); p2.getBuildersList().add(p2Builder); FreeStyleProject p3 = j.createFreeStyleProject("p3"); p3.addProperty(new RequiredResourcesProperty("resource1", null, "1", null, null)); SemaphoreBuilder p3Builder = new SemaphoreBuilder(); p3.getBuildersList().add(p3Builder); final QueueTaskFuture<FreeStyleBuild> taskA = p3.scheduleBuild2(0, new TimerTrigger.TimerTriggerCause()); TestHelpers.waitForQueue(j.jenkins, p3); final QueueTaskFuture<FreeStyleBuild> taskB = p2.scheduleBuild2(0, new TimerTrigger.TimerTriggerCause()); p3Builder.release(); final FreeStyleBuild buildA = taskA.get(60, TimeUnit.SECONDS); p2Builder.release(); final FreeStyleBuild buildB = taskB.get(60, TimeUnit.SECONDS); long buildAEndTime = buildA.getStartTimeInMillis() + buildA.getDuration(); assertTrue( "Project A build should be finished before the build of project B starts. " + "A finished at " + buildAEndTime + ", B started at " + buildB.getStartTimeInMillis(), buildB.getStartTimeInMillis() >= buildAEndTime); }
Example 17
Source File: UsernamePasswordBindingTest.java From credentials-binding-plugin with MIT License | 4 votes |
@Test public void theSecretBuildWrapperTracksUsage() throws Exception { SystemCredentialsProvider.getInstance().setDomainCredentialsMap( Collections.singletonMap(Domain.global(), Collections.<Credentials>emptyList())); for (CredentialsStore s : CredentialsProvider.lookupStores(Jenkins.getInstance())) { if (s.getProvider() instanceof SystemCredentialsProvider.ProviderImpl) { store = s; break; } } assertThat("The system credentials provider is enabled", store, notNullValue()); UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "secret-id", "test credentials", "bob", "secret"); store.addCredentials(Domain.global(), credentials); Fingerprint fingerprint = CredentialsProvider.getFingerprintOf(credentials); assertThat("No fingerprint created until first use", fingerprint, nullValue()); JenkinsRule.WebClient wc = r.createWebClient(); HtmlPage page = wc.goTo("credentials/store/system/domain/_/credentials/secret-id"); assertThat("Have usage tracking reported", page.getElementById("usage"), notNullValue()); assertThat("No fingerprint created until first use", page.getElementById("usage-missing"), notNullValue()); assertThat("No fingerprint created until first use", page.getElementById("usage-present"), nullValue()); FreeStyleProject job = r.createFreeStyleProject(); // add a parameter job.addProperty(new ParametersDefinitionProperty( new CredentialsParameterDefinition( "SECRET", "The secret", "secret-id", Credentials.class.getName(), false ))); r.assertBuildStatusSuccess((Future) job.scheduleBuild2(0, new ParametersAction(new CredentialsParameterValue("SECRET", "secret-id", "The secret", true)))); fingerprint = CredentialsProvider.getFingerprintOf(credentials); assertThat("A job that does nothing does not use parameterized credentials", fingerprint, nullValue()); page = wc.goTo("credentials/store/system/domain/_/credentials/secret-id"); assertThat("Have usage tracking reported", page.getElementById("usage"), notNullValue()); assertThat("No fingerprint created until first use", page.getElementById("usage-missing"), notNullValue()); assertThat("No fingerprint created until first use", page.getElementById("usage-present"), nullValue()); // check that the wrapper works as expected job.getBuildWrappersList().add(new SecretBuildWrapper(Collections.<Binding<?>>singletonList(new UsernamePasswordBinding("AUTH", credentials.getId())))); r.assertBuildStatusSuccess((Future) job.scheduleBuild2(0, new ParametersAction(new CredentialsParameterValue("SECRET", "secret-id", "The secret", true)))); fingerprint = CredentialsProvider.getFingerprintOf(credentials); assertThat(fingerprint, notNullValue()); assertThat(fingerprint.getJobs(), hasItem(is(job.getFullName()))); Fingerprint.RangeSet rangeSet = fingerprint.getRangeSet(job); assertThat(rangeSet, notNullValue()); assertThat(rangeSet.includes(job.getLastBuild().getNumber()), is(true)); page = wc.goTo("credentials/store/system/domain/_/credentials/secret-id"); assertThat(page.getElementById("usage-missing"), nullValue()); assertThat(page.getElementById("usage-present"), notNullValue()); assertThat(page.getAnchorByText(job.getFullDisplayName()), notNullValue()); // check the API WebResponse response = wc.goTo( "credentials/store/system/domain/_/credentials/secret-id/api/xml?depth=1&xpath=*/fingerprint/usage", "application/xml").getWebResponse(); assertThat(response.getContentAsString(), CompareMatcher.isSimilarTo("<usage>" + "<name>"+ Util.xmlEscape(job.getFullName())+"</name>" + "<ranges>" + "<range>" + "<end>"+(job.getLastBuild().getNumber()+1)+"</end>" + "<start>" + job.getLastBuild().getNumber()+"</start>" + "</range>" + "</ranges>" + "</usage>").ignoreWhitespace().ignoreComments()); }
Example 18
Source File: AutoResubmitIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
@Test public void should_successfully_resubmit_parametrized_task() throws Exception { EC2FleetCloud cloud = new EC2FleetCloud(null, null, "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 0, 0, 10, 1, false, false, false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud); List<QueueTaskFuture> rs = new ArrayList<>(); final FreeStyleProject project = j.createFreeStyleProject(); project.setAssignedLabel(new LabelAtom("momo")); project.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("number", "opa"))); /* example of actions for project actions = {CopyOnWriteArrayList@14845} size = 2 0 = {ParametersAction@14853} safeParameters = {TreeSet@14855} size = 0 parameters = {ArrayList@14856} size = 1 0 = {StringParameterValue@14862} "(StringParameterValue) number='1'" value = "1" name = "number" description = "" parameterDefinitionNames = {ArrayList@14857} size = 1 0 = "number" build = null run = {FreeStyleBuild@14834} "parameter #14" */ project.getBuildersList().add(Functions.isWindows() ? new BatchFile("Ping -n %number% 127.0.0.1 > nul") : new Shell("sleep ${number}")); rs.add(project.scheduleBuild2(0, new ParametersAction(new StringParameterValue("number", "30")))); System.out.println("check if zero nodes!"); Assert.assertEquals(0, j.jenkins.getNodes().size()); assertAtLeastOneNode(); final Node node = j.jenkins.getNodes().get(0); assertQueueIsEmpty(); System.out.println("disconnect node"); node.toComputer().disconnect(new OfflineCause.ChannelTermination(new UnsupportedOperationException("Test"))); assertLastBuildResult(Result.FAILURE, Result.ABORTED); node.toComputer().connect(true); assertNodeIsOnline(node); assertQueueAndNodesIdle(node); Assert.assertEquals(1, j.jenkins.getProjects().size()); Assert.assertEquals(Result.SUCCESS, j.jenkins.getProjects().get(0).getLastBuild().getResult()); Assert.assertEquals(2, j.jenkins.getProjects().get(0).getBuilds().size()); cancelTasks(rs); }
Example 19
Source File: GitHubPRTriggerTest.java From github-integration-plugin with MIT License | 2 votes |
@LocalData @Test public void buildButtonsPerms() throws Exception { j.getInstance().setNumExecutors(0); j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); ProjectMatrixAuthorizationStrategy auth = new ProjectMatrixAuthorizationStrategy(); auth.add(Jenkins.READ, "alice"); auth.add(Computer.BUILD, "alice"); auth.add(Jenkins.ADMINISTER, "admin"); auth.add(Jenkins.READ, "bob"); auth.add(Computer.BUILD, "bob"); j.jenkins.setAuthorizationStrategy(auth); final FreeStyleProject project = (FreeStyleProject) j.getInstance().getItem("project"); Map<Permission,Set<String>> perms = new HashMap<>(); HashSet<String> users = new HashSet<>(); users.add("alice"); users.add("bob"); perms.put(Item.READ, users); perms.put(Item.BUILD, Collections.singleton("bob")); project.addProperty(new AuthorizationMatrixProperty(perms)); JenkinsRule.WebClient webClient = j.createWebClient(); webClient = webClient.login("bob", "bob"); HtmlPage repoPage = webClient.getPage(project, "github-pullrequest"); HtmlForm form = repoPage.getFormByName("rebuildAllFailed"); HtmlFormUtil.getButtonByCaption(form, "Rebuild all failed builds").click(); HtmlPage page = (HtmlPage) submit(form); Queue.Item[] items = j.getInstance().getQueue().getItems(); assertThat(items, arrayWithSize(0)); }
Example 20
Source File: GitHubBranchTriggerTest.java From github-integration-plugin with MIT License | 2 votes |
@LocalData @Test public void buildButtonsPerms() throws Exception { jRule.getInstance().setNumExecutors(0); jRule.jenkins.setSecurityRealm(jRule.createDummySecurityRealm()); ProjectMatrixAuthorizationStrategy auth = new ProjectMatrixAuthorizationStrategy(); auth.add(Jenkins.READ, "alice"); auth.add(Computer.BUILD, "alice"); auth.add(Jenkins.ADMINISTER, "admin"); auth.add(Jenkins.READ, "bob"); auth.add(Computer.BUILD, "bob"); jRule.jenkins.setAuthorizationStrategy(auth); final FreeStyleProject project = (FreeStyleProject) jRule.getInstance().getItem("project"); Map<Permission, Set<String>> perms = new HashMap<>(); HashSet<String> users = new HashSet<>(); users.add("alice"); users.add("bob"); perms.put(Item.READ, users); perms.put(Item.BUILD, Collections.singleton("bob")); project.addProperty(new AuthorizationMatrixProperty(perms)); JenkinsRule.WebClient webClient = jRule.createWebClient(); webClient = webClient.login("bob", "bob"); HtmlPage repoPage = webClient.getPage(project, "github-branch"); HtmlForm form = repoPage.getFormByName("rebuildAllFailed"); HtmlFormUtil.getButtonByCaption(form, "Rebuild all failed builds").click(); HtmlPage page = (HtmlPage) submit(form); Queue.Item[] items = jRule.getInstance().getQueue().getItems(); assertThat(items, arrayWithSize(0)); }