hudson.model.queue.QueueListener Java Examples
The following examples show how to use
hudson.model.queue.QueueListener.
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: MergeRequestBuildActionTest.java From gitlab-plugin with GNU General Public License v2.0 | 6 votes |
@BeforeClass public static void addQueueListener() { QueueListener ql = new QueueListener() { @Override public void onEnterWaiting(Queue.WaitingItem wi) { System.out.println("Got "+wi+" : "+wi.getCausesDescription()); wouldFire = true; } @Override public void onEnterBuildable(Queue.BuildableItem bi) { System.out.println("Is buildable: "+bi.getCausesDescription()); } }; jenkins.getInstance().getExtensionList(QueueListener.class).add(ql); }
Example #2
Source File: GitLabPipelineStatusNotifier.java From gitlab-branch-source-plugin with MIT License | 4 votes |
/** * Sends notifications to GitLab on Checkout (for the "In Progress" Status). */ private static void sendNotifications(Run<?, ?> build, TaskListener listener) { GitLabSCMSource source = getSource(build); if (source == null) { return; } final GitLabSCMSourceContext sourceContext = getSourceContext(build, source); if (sourceContext.notificationsDisabled()) { return; } String url = getRootUrl(build); if (url.isEmpty()) { listener.getLogger().println( "Can not determine Jenkins root URL. Commit status notifications are disabled until a root URL is" + " configured in Jenkins global configuration."); return; } Result result = build.getResult(); LOGGER.log(Level.FINE, String.format("Result: %s", result)); CommitStatus status = new CommitStatus(); Constants.CommitBuildState state; status.setTargetUrl(url); if (Result.SUCCESS.equals(result)) { status.setDescription(build.getParent().getFullName() + ": This commit looks good"); status.setStatus("SUCCESS"); state = Constants.CommitBuildState.SUCCESS; } else if (Result.UNSTABLE.equals(result)) { status.setDescription( build.getParent().getFullName() + ": This commit has test failures"); status.setStatus("FAILED"); state = Constants.CommitBuildState.FAILED; } else if (Result.FAILURE.equals(result)) { status.setDescription( build.getParent().getFullName() + ": There was a failure building this commit"); status.setStatus("FAILED"); state = Constants.CommitBuildState.FAILED; } else if (result != null) { // ABORTED, NOT_BUILT. status.setDescription(build.getParent().getFullName() + ": Something is wrong with the build of this commit"); status.setStatus("CANCELED"); state = Constants.CommitBuildState.CANCELED; } else { status.setDescription(build.getParent().getFullName() + ": Build started..."); status.setStatus("RUNNING"); state = Constants.CommitBuildState.RUNNING; } final SCMRevision revision = SCMRevisionAction.getRevision(source, build); String hash; if (revision instanceof BranchSCMRevision) { listener.getLogger() .format("[GitLab Pipeline Status] Notifying branch build status: %s %s%n", status.getStatus(), status.getDescription()); hash = ((BranchSCMRevision) revision).getHash(); } else if (revision instanceof MergeRequestSCMRevision) { listener.getLogger() .format("[GitLab Pipeline Status] Notifying merge request build status: %s %s%n", status.getStatus(), status.getDescription()); hash = ((MergeRequestSCMRevision) revision).getOrigin().getHash(); } else if (revision instanceof GitTagSCMRevision) { listener.getLogger() .format("[GitLab Pipeline Status] Notifying tag build status: %s %s%n", status.getStatus(), status.getDescription()); hash = ((GitTagSCMRevision) revision).getHash(); } else { return; } status.setName(getStatusName(sourceContext, build, revision)); final JobScheduledListener jsl = ExtensionList.lookup(QueueListener.class) .get(JobScheduledListener.class); if (jsl != null) { // we are setting the status, so don't let the queue listener background thread change it to pending synchronized (jsl.resolving) { jsl.resolving.remove(build.getParent()); } } try { GitLabApi gitLabApi = GitLabHelper.apiBuilder(source.getServerName()); LOGGER.log(Level.FINE, String.format("Notifiying commit: %s", hash)); gitLabApi.getCommitsApi().addCommitStatus( source.getProjectPath(), hash, state, status); listener.getLogger().format("[GitLab Pipeline Status] Notified%n"); } catch (GitLabApiException e) { if(!e.getMessage().contains(("Cannot transition status"))) { LOGGER.log(Level.WARNING, String.format("Exception caught: %s",e.getMessage())); } } }