hudson.model.BuildListener Java Examples
The following examples show how to use
hudson.model.BuildListener.
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: ZAProxy.java From zaproxy-plugin with MIT License | 6 votes |
/** * set up script based authentication method for the created context * @author Abdellah AZOUGARH * @param listener the listener to display log during the job execution in jenkins * @param zapClientAPI the ZAP API client * @param scriptName the name of the authentication script used to authenticate the user * @param scriptLoggedInIndicator the indication that the user is logged in * @throws UnsupportedEncodingException * @throws ClientApiException */ private void setUpScriptBasedAuthenticationMethod( BuildListener listener, ClientApi zapClientAPI,String scriptName , String contextId, String scriptLoggedInIndicator) throws UnsupportedEncodingException, ClientApiException { // set script based authentication method // Prepare the configuration in a format similar to how URL parameters are formed. This // means that any value we add for the configuration values has to be URL encoded. StringBuilder scriptBasedConfig = new StringBuilder(); scriptBasedConfig.append("scriptName=").append(URLEncoder.encode(scriptName, "UTF-8")); listener.getLogger().println("Setting Script based authentication configuration as: " + scriptBasedConfig.toString()); zapClientAPI.authentication.setAuthenticationMethod(API_KEY, contextId, "scriptBasedAuthentication",scriptBasedConfig.toString()); listener.getLogger().println("Authentication config: " + zapClientAPI.authentication.getAuthenticationMethod(contextId).toString(0)); //add logged in idicator if (!scriptLoggedInIndicator.equals("")) { listener.getLogger().println("---------------------------------------"); zapClientAPI.authentication.setLoggedInIndicator(API_KEY,contextId, scriptLoggedInIndicator ); } }
Example #2
Source File: JUnitResultArchiverTest.java From junit-plugin with MIT License | 6 votes |
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { FilePath ws = build.getWorkspace(); OutputStream os = ws.child(name + ".xml").write(); try { PrintWriter pw = new PrintWriter(os); pw.println("<testsuite failures=\"" + fail + "\" errors=\"0\" skipped=\"0\" tests=\"" + (pass + fail) + "\" name=\"" + name + "\">"); for (int i = 0; i < pass; i++) { pw.println("<testcase classname=\"" + name + "\" name=\"passing" + i + "\"/>"); } for (int i = 0; i < fail; i++) { pw.println("<testcase classname=\"" + name + "\" name=\"failing" + i + "\"><error message=\"failure\"/></testcase>"); } pw.println("</testsuite>"); pw.flush(); } finally { os.close(); } new JUnitResultArchiver(name + ".xml").perform(build, ws, launcher, listener); return true; }
Example #3
Source File: ZAProxy.java From zaproxy-plugin with MIT License | 6 votes |
/** * Scan all pages found at url and raised actives alerts * * @author abdellah.azougarh * @param url the url to scan * @param listener the listener to display log during the job execution in jenkins * @param zapClientAPI the client API to use ZAP API methods * @param contextId the id number of the contexte created for this scan * @param userId the id number of the user created for this scan * @throws ClientApiException * @throws InterruptedException */ private void scanURLAsUser(final String url, BuildListener listener, ClientApi zapClientAPI, String contextId, String userId) throws ClientApiException, InterruptedException { if(chosenPolicy == null || chosenPolicy.isEmpty()) { listener.getLogger().println("Scan url [" + url + "] with the policy by default"); } else { listener.getLogger().println("Scan url [" + url + "] with the following policy [" + chosenPolicy + "]"); } // Method signature : scan(String apikey, String url, String recurse, String inscopeonly, String scanpolicyname, String method, String postdata) // Use a default policy if chosenPolicy is null or empty zapClientAPI.ascan.scanAsUser(API_KEY, url, contextId, userId,"true", chosenPolicy, null, null);//arg2, arg3, arg4, arg5, arg6, arg7)scan(API_KEY, url, "true", "false", chosenPolicy, null, null); // Wait for complete scanning (equal to 100) // Method signature : status(String scanId) while (statusToInt(zapClientAPI.ascan.status("")) < 100) { listener.getLogger().println("Status scan = " + statusToInt(zapClientAPI.ascan.status("")) + "%"); listener.getLogger().println("Alerts number = " + zapClientAPI.core.numberOfAlerts("").toString(2)); listener.getLogger().println("Messages number = " + zapClientAPI.core.numberOfMessages("").toString(2)); Thread.sleep(5000); } }
Example #4
Source File: ZAProxy.java From zaproxy-plugin with MIT License | 6 votes |
/** * Search for all links and pages on the URL and raised passives alerts * @author thilina27 * @param url the url to investigate * @param listener the listener to display log during the job execution in jenkins * @param zapClientAPI the client API to use ZAP API methods * @param contextId the id number of the contexte created for this scan * @param userId the id number of the user created for this scan * @throws ClientApiException * @throws InterruptedException */ private void spiderURLAsUser(final String url, BuildListener listener, ClientApi zapClientAPI, String contextId, String userId) throws ClientApiException, InterruptedException { // Start spider as user zapClientAPI.spider.scanAsUser(API_KEY, url, contextId, userId, "0", ""); // Wait for complete spidering (equal to 100) // Method signature : status(String scanId) while (statusToInt(zapClientAPI.spider.status("")) < 100) { listener.getLogger().println("Status spider = " + statusToInt(zapClientAPI.spider.status("")) + "%"); listener.getLogger().println("Alerts number = " + zapClientAPI.core.numberOfAlerts("").toString(2)); Thread.sleep(1000); } }
Example #5
Source File: DockerBuilderNewTemplate.java From docker-plugin with MIT License | 6 votes |
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { final PrintStream llogger = listener.getLogger(); final String dockerImage = dockerTemplate.getDockerTemplateBase().getImage(); // Job must run as Admin as we are changing global cloud configuration here. build.getACL().checkPermission(Jenkins.ADMINISTER); for (Cloud c : Jenkins.getInstance().clouds) { if (c instanceof DockerCloud && dockerImage != null) { DockerCloud dockerCloud = (DockerCloud) c; if (dockerCloud.getTemplate(dockerImage) == null) { LOGGER.info("Adding new template: '{}', to cloud: '{}'", dockerImage, dockerCloud.name); llogger.println("Adding new template: '" + dockerImage + "', to cloud: '" + dockerCloud.name + "'"); dockerCloud.addTemplate(dockerTemplate); } } } return true; }
Example #6
Source File: JUnitParserTest.java From junit-plugin with MIT License | 6 votes |
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { System.out.println("in perform..."); // First touch all the files, so they will be recently modified for (FilePath f : build.getWorkspace().list()) { f.touch(System.currentTimeMillis()); } System.out.println("...touched everything"); hudson.tasks.junit.TestResult result = (new JUnitParser()).parseResult(testResultLocation, build, null, build.getWorkspace(), launcher, listener); System.out.println("back from parse"); assertNotNull("we should have a non-null result", result); assertTrue("result should be a TestResult", result instanceof hudson.tasks.junit.TestResult); System.out.println("We passed some assertions in the JUnitParserTestBuilder"); theResult = result; return result != null; }
Example #7
Source File: JiraBuildStepPublisherTest.java From jira-ext-plugin with Apache License 2.0 | 6 votes |
@Test public void testInvokeOperations() { IssueStrategyExtension mockStrategy = mock(IssueStrategyExtension.class); JiraOperationExtension mockOperation = mock(JiraOperationExtension.class); Descriptor mockDescriptor = mock(Descriptor.class); when(mockDescriptor.getDisplayName()).thenReturn("Mock descriptor"); when(mockOperation.getDescriptor()).thenReturn(mockDescriptor); JiraExtBuildStep builder = new JiraExtBuildStep(mockStrategy, Arrays.asList(mockOperation)); List<JiraCommit> commits = Arrays.asList(new JiraCommit("JENKINS-101", MockChangeLogUtil.mockChangeLogSetEntry("example ticket"))); when(mockStrategy.getJiraCommits(any(AbstractBuild.class), any(BuildListener.class))) .thenReturn(commits); assertTrue(builder.perform(mock(AbstractBuild.class), mock(Launcher.class), new StreamBuildListener(System.out))); verify(mockOperation).perform(eq(commits), any(AbstractBuild.class), any(Launcher.class), any(BuildListener.class)); }
Example #8
Source File: ZAProxy.java From zaproxy-plugin with MIT License | 6 votes |
/** * Search for all links and pages on the URL and raised passives alerts * @author thilina27 * @param url the url to investigate * @param listener the listener to display log during the job execution in jenkins * @param zapClientAPI the client API to use ZAP API methods * @throws ClientApiException * @throws InterruptedException */ private void ajaxSpiderURL(final String url, BuildListener listener, ClientApi zapClientAPI) throws ClientApiException, InterruptedException{ //Method signature : scan(String apikey,String url,String inscope) zapClientAPI.ajaxSpider.scan(API_KEY, url, "false"); // Wait for complete spidering (equal to status complete) // Method signature : status(String scanId) while ("running".equalsIgnoreCase(statusToString(zapClientAPI.ajaxSpider.status()))) { listener.getLogger().println("Status spider = " + statusToString(zapClientAPI.ajaxSpider.status())); listener.getLogger().println("Alerts number = " + zapClientAPI.core.numberOfAlerts("").toString(2)); Thread.sleep(2500); } }
Example #9
Source File: CompressionTools.java From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 | 6 votes |
public static void compressZipFile( final File temporaryZipFile, final Path pathToCompress, final BuildListener listener) throws IOException { try (final ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream( new BufferedOutputStream( new FileOutputStream(temporaryZipFile)))) { compressArchive( pathToCompress, zipArchiveOutputStream, new ArchiveEntryFactory(CompressionType.Zip), CompressionType.Zip, listener); } }
Example #10
Source File: ZAProxy.java From zaproxy-plugin with MIT License | 6 votes |
/** * Set up all authentication details * @author thilina27 * @param username user name to be used in authentication * @param password password for the authentication user * @param usernameParameter parameter define in passing username * @param passwordParameter parameter that define in passing password for the user * @param extraPostData other post data than credentials * @param loginUrl login page url * @param loggedInIdicator indication for know its logged in * @throws ClientApiException * @throws InterruptedException * @throws UnsupportedEncodingException */ private void setUpAuthentication( String authenticationMethod,BuildListener listener, ClientApi zapClientAPI, String username, String password, String usernameParameter, String passwordParameter, String extraPostData, String loginUrl, String loggedInIndicator,String scriptName) throws ClientApiException, UnsupportedEncodingException { //setup context //this.contextId=setUpContext(listener,url,zapClientAPI); //set up authentication method if(authenticationMethod.equals("FORMBASED")){ setUpFormBasedAuthenticationMethod(listener,zapClientAPI,loggedInIndicator,usernameParameter, passwordParameter,extraPostData,contextId,loginUrl); } else if(authenticationMethod.equals("SCRIPTBASED")){ setUpScriptBasedAuthenticationMethod(listener, zapClientAPI, scriptName , contextId, loggedInIndicator); } //set up user this.userId=setUpUser(listener,zapClientAPI,username,password,contextId); }
Example #11
Source File: UpdateField.java From jira-ext-plugin with Apache License 2.0 | 6 votes |
@Override public void perform(List<JiraCommit> commits, AbstractBuild build, Launcher launcher, BuildListener listener) { for (JiraCommit commit : JiraCommit.filterDuplicateIssues(commits)) { try { String expandedValue = build.getEnvironment(listener).expand(fieldValue); getJiraClientSvc().updateStringField(commit.getJiraTicket(), fieldName, expandedValue); } catch (Throwable t) { listener.getLogger().println("Error updating ticket, continuing"); t.printStackTrace(listener.getLogger()); } } }
Example #12
Source File: DownstreamJobPlugin.java From DotCi with MIT License | 6 votes |
@Override public boolean perform(DynamicBuild dynamicBuild, Launcher launcher, BuildListener listener) { if (!(options instanceof Map)) { throw new InvalidBuildConfigurationException("Invalid format specified for " + getName() + " . Expecting a Map."); } Map<String, Object> jobOptions = (Map<String, Object>) options; if (shouldKickOffJob(dynamicBuild, jobOptions)) { String jobName = getJobName(jobOptions); DynamicProject job = findJob(jobName); Map<String, String> jobParams = new HashMap<String, String>((Map<String, String>) jobOptions.get(jobName)); jobParams.put("SOURCE_BUILD", getSourceBuildNumber(dynamicBuild)); listener.getLogger().println("Lauching dowstream job :" + job.getFullName()); return job.scheduleBuild(0, getCause(dynamicBuild, job, jobOptions.get(jobName)), getParamsAction(jobParams)); } return true; }
Example #13
Source File: ExtractResourceSCM.java From jenkins-test-harness with MIT License | 5 votes |
@Override public boolean checkout(AbstractBuild<?,?> build, Launcher launcher, FilePath workspace, BuildListener listener, File changeLogFile) throws IOException, InterruptedException { if (workspace.exists()) { listener.getLogger().println("Deleting existing workspace " + workspace.getRemote()); workspace.deleteRecursive(); } listener.getLogger().println("Staging "+zip); workspace.unzipFrom(zip.openStream()); if (parentFolder != null) { FileUtils.copyDirectory( new File(workspace.getRemote() + "/" + parentFolder), new File( workspace.getRemote())); } return true; }
Example #14
Source File: WorkspaceWriter.java From jenkins-test-harness with MIT License | 5 votes |
@Override public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener ) throws InterruptedException, IOException { build.getWorkspace().child(path).write(content, "UTF-8"); return true; }
Example #15
Source File: Binding.java From credentials-binding-plugin with MIT License | 5 votes |
@Deprecated @SuppressWarnings("rawtypes") public Environment bind(@Nonnull final AbstractBuild build, final Launcher launcher, final BuildListener listener) throws IOException, InterruptedException { final SingleEnvironment e = bindSingle(build, build.getWorkspace(), launcher, listener); return new Environment() { @Override public String value() { return e.value; } @Override public void unbind() throws IOException, InterruptedException { e.unbinder.unbind(build, build.getWorkspace(), launcher, listener); } }; }
Example #16
Source File: SingleTicketStrategyTest.java From jira-ext-plugin with Apache License 2.0 | 5 votes |
@Test public void testErrorInExpansion() throws Exception { AbstractBuild mockBuild = mock(AbstractBuild.class); SingleTicketStrategy strategy = new SingleTicketStrategy("$FOO"); when(mockBuild.getEnvironment(any(BuildListener.class))).thenThrow(new IOException()); List<JiraCommit> commits = strategy.getJiraCommits(mockBuild, new StreamBuildListener(System.out, Charset.defaultCharset())); assertEquals(1, commits.size()); assertEquals("$FOO", commits.get(0).getJiraTicket()); }
Example #17
Source File: IssuesRecorder.java From warnings-ng-plugin with MIT License | 5 votes |
@Override public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener) throws InterruptedException, IOException { FilePath workspace = build.getWorkspace(); if (workspace == null) { throw new IOException("No workspace found for " + build); } perform(build, workspace, listener, new RunResultHandler(build)); return true; }
Example #18
Source File: DockerComposeBuild.java From DotCi with MIT License | 5 votes |
private Result runPlugins(final DynamicBuild dynamicBuild, final List<DotCiPluginAdapter> plugins, final BuildListener listener, final Launcher launcher) { boolean result = true; for (final DotCiPluginAdapter plugin : plugins) { result = result & plugin.perform(dynamicBuild, launcher, listener); } return result ? Result.SUCCESS : Result.FAILURE; }
Example #19
Source File: TestUtility.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
static <T extends Notifier & MatrixAggregatable> void verifyMatrixAggregatable(Class<T> publisherClass, BuildListener listener) throws InterruptedException, IOException { AbstractBuild build = mock(AbstractBuild.class); AbstractProject project = mock(MatrixConfiguration.class); Notifier publisher = mock(publisherClass); MatrixBuild parentBuild = mock(MatrixBuild.class); when(build.getParent()).thenReturn(project); when(((MatrixAggregatable) publisher).createAggregator(any(MatrixBuild.class), any(Launcher.class), any(BuildListener.class))).thenCallRealMethod(); when(publisher.perform(any(AbstractBuild.class), any(Launcher.class), any(BuildListener.class))).thenReturn(true); MatrixAggregator aggregator = ((MatrixAggregatable) publisher).createAggregator(parentBuild, null, listener); aggregator.startBuild(); aggregator.endBuild(); verify(publisher).perform(parentBuild, null, listener); }
Example #20
Source File: EmailNotifierBase.java From DotCi with MIT License | 5 votes |
protected List<InternetAddress> getToEmailAddress(DynamicBuild build, BuildListener listener) throws AddressException { List<InternetAddress> addresses = new ArrayList<InternetAddress>(); List<String> emails = getNotificationEmails(build); if (emails != null) { for (String email : emails) { if (email != null) { addresses.add(new InternetAddress(email)); } } } return addresses; }
Example #21
Source File: TouchBuilder.java From jenkins-test-harness with MIT License | 5 votes |
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { for (FilePath f : build.getWorkspace().list()) { f.touch(System.currentTimeMillis()); } return true; }
Example #22
Source File: PhabricatorBuildWrapper.java From phabricator-jenkins-plugin with MIT License | 5 votes |
/** * Abort running builds when new build referencing same revision is scheduled to run */ @Override public void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { String abortOnRevisionId = getAbortOnRevisionId(build); // If ABORT_ON_REVISION_ID is available if (!CommonUtils.isBlank(abortOnRevisionId)) { // Create a cause of interruption PhabricatorCauseOfInterruption causeOfInterruption = new PhabricatorCauseOfInterruption(build.getUrl()); Run upstreamRun = getUpstreamRun(build); // Get the running builds that were scheduled before the current one RunList<AbstractBuild> runningBuilds = (RunList<AbstractBuild>) build.getProject().getBuilds(); for (AbstractBuild runningBuild : runningBuilds) { Executor executor = runningBuild.getExecutor(); Run runningBuildUpstreamRun = getUpstreamRun(runningBuild); // Ignore builds that were triggered by the same upstream build // Find builds triggered with the same ABORT_ON_REVISION_ID_FIELD if (runningBuild.isBuilding() && runningBuild.number < build.number && abortOnRevisionId.equals(getAbortOnRevisionId(runningBuild)) && (upstreamRun == null || runningBuildUpstreamRun == null || !upstreamRun.equals(runningBuildUpstreamRun)) && executor != null) { // Abort the builds executor.interrupt(Result.ABORTED, causeOfInterruption); } } } }
Example #23
Source File: DockerComposeBuild.java From DotCi with MIT License | 5 votes |
private Result runParallelBuild(final DynamicBuild dynamicBuild, final BuildExecutionContext buildExecutionContext, final BuildConfiguration buildConfiguration, final BuildListener listener) throws IOException, InterruptedException { final SubBuildScheduler subBuildScheduler = new SubBuildScheduler(dynamicBuild, this, new SubBuildScheduler.SubBuildFinishListener() { @Override public void runFinished(final DynamicSubBuild subBuild) throws IOException { for (final DotCiPluginAdapter plugin : buildConfiguration.getPlugins()) { plugin.runFinished(subBuild, dynamicBuild, listener); } } }); try { final Iterable<Combination> axisList = buildConfiguration.getAxisList().list(); Result runResult = subBuildScheduler.runSubBuilds(axisList, listener); if (runResult.equals(Result.SUCCESS)) { final Result afterRunResult = runAfterCommands(buildExecutionContext, listener); runResult = runResult.combine(afterRunResult); } dynamicBuild.setResult(runResult); return runResult; } finally { try { subBuildScheduler.cancelSubBuilds(listener.getLogger()); } catch (final Exception e) { // There is nothing much we can do at this point } } }
Example #24
Source File: GitLabCommitStatusPublisher.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
public MatrixAggregator createAggregator(MatrixBuild build, Launcher launcher, BuildListener listener) { return new MatrixAggregator(build, launcher, listener) { @Override public boolean endBuild() throws InterruptedException, IOException { perform(build, launcher, listener); return super.endBuild(); } }; }
Example #25
Source File: RemoteFileFetcherTest.java From phabricator-jenkins-plugin with MIT License | 5 votes |
private Builder echoBuilder(final String fileName, final String content) { return new TestBuilder() { @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child(fileName).write(content, "UTF-8"); return true; } }; }
Example #26
Source File: JiraExtPublisherStep.java From jira-ext-plugin with Apache License 2.0 | 5 votes |
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { listener.getLogger().println("Updating JIRA tickets"); List<JiraCommit> commits = issueStrategy.getJiraCommits(build, listener); for (JiraOperationExtension extension : extensions) { listener.getLogger().println("Operation: " + extension.getDescriptor().getDisplayName()); extension.perform(commits, build, launcher, listener); } listener.getLogger().println("Finish updating JIRA tickets"); return true; }
Example #27
Source File: EmailNotifierBase.java From DotCi with MIT License | 5 votes |
@Override public boolean notify(DynamicBuild build, BuildListener listener) { debug(listener.getLogger(), "Sending email notifications"); if (needsEmail(build, listener)) { sendMail(listener, build); } return true; }
Example #28
Source File: RepairnatorPostBuild.java From repairnator with MIT License | 5 votes |
public void printAllEnv(AbstractBuild build,BuildListener listener) throws IOException,InterruptedException{ System.out.println("-----------Printing Env----------"); final EnvVars env = build.getEnvironment(listener); for(String key : env.keySet()) { System.out.println(key + ":" + env.get(key)); } System.out.println("---------------------------------"); }
Example #29
Source File: MattermostListener.java From jenkins-mattermost-plugin with MIT License | 5 votes |
@SuppressWarnings("unchecked") FineGrainedNotifier getNotifier(AbstractProject project, TaskListener listener) { Map<Descriptor<Publisher>, Publisher> map = project.getPublishersList().toMap(); for (Publisher publisher : map.values()) { if (publisher instanceof MattermostNotifier) { return new ActiveNotifier((MattermostNotifier) publisher, (BuildListener) listener, new JenkinsTokenExpander(listener)); } } return new DisabledNotifier(); }
Example #30
Source File: GroovyJenkinsRule.java From jenkins-test-harness with MIT License | 5 votes |
/** * Wraps a closure as a {@link Builder}. */ public Builder builder(final Closure c) { return new TestBuilder() { @Override public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { Object r = c.call(new Object[] {build, launcher, listener}); if (r instanceof Boolean) { return (Boolean) r; } return true; } }; }