jenkins.triggers.SCMTriggerItem Java Examples
The following examples show how to use
jenkins.triggers.SCMTriggerItem.
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: GiteaWebhookListener.java From gitea-plugin with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public void onChange(Saveable o, XmlFile file) { if (!(o instanceof Item)) { // must be an Item return; } SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem((Item) o); if (item == null) { // more specifically must be an SCMTriggerItem return; } SCMTrigger trigger = item.getSCMTrigger(); if (trigger == null || trigger.isIgnorePostCommitHooks()) { // must have the trigger enabled and not opted out of post commit hooks return; } for (SCM scm : item.getSCMs()) { if (scm instanceof GitSCM) { // we have a winner GiteaWebhookListener.register(item, (GitSCM) scm); } } }
Example #2
Source File: HistoryAggregatedFlakyTestResultAction.java From flaky-test-handler-plugin with Apache License 2.0 | 6 votes |
/** * Construct a SingleTestFlakyStatsWithRevision object with {@link SingleTestFlakyStats} and * build information. * * @param stats Embedded {@link SingleTestFlakyStats} object * @param build The {@link hudson.model.Run} object to get SCM information from. */ public SingleTestFlakyStatsWithRevision(SingleTestFlakyStats stats, Run build) { this.stats = stats; revision = Integer.toString(build.getNumber()); Job job = build.getParent(); SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job); if (s != null) { ArrayList<SCM> scms = new ArrayList<>(s.getSCMs()); SCM scm = scms.size() > 0 ? scms.get(0) : null; if (scm != null && "hudson.plugins.git.GitSCM".equalsIgnoreCase(scm.getType())) { GitSCM gitSCM = (GitSCM) scm; BuildData buildData = gitSCM.getBuildData(build); if (buildData != null) { Revision gitRevision = buildData.getLastBuiltRevision(); if (gitRevision != null) { revision = gitRevision.getSha1String(); } } } } }
Example #3
Source File: BuildStatusAction.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
public void execute(StaplerResponse response) { SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(project); if (!hasGitSCM(item)) { throw HttpResponses.error(409, "The project has no GitSCM configured"); } writeStatusBody(response, build, getStatus(build)); }
Example #4
Source File: BuildStatusAction.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private boolean hasGitSCM(SCMTriggerItem item) { if (item != null) { for (SCM scm : item.getSCMs()) { if (scm instanceof GitSCM) { return true; } } } return false; }
Example #5
Source File: AbstractWebHookTriggerHandler.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
protected Action[] createActions(Job<?, ?> job, H hook) { ArrayList<Action> actions = new ArrayList<>(); actions.add(new CauseAction(new GitLabWebHookCause(retrieveCauseData(hook)))); try { SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job); GitSCM gitSCM = getGitSCM(item); actions.add(createRevisionParameter(hook, gitSCM)); } catch (NoRevisionToBuildException e) { LOGGER.log(Level.WARNING, "unknown handled situation, dont know what revision to build for req {0} for job {1}", new Object[]{hook, (job != null ? job.getFullName() : null)}); } return actions.toArray(new Action[actions.size()]); }
Example #6
Source File: AbstractWebHookTriggerHandler.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private GitSCM getGitSCM(SCMTriggerItem item) { if (item != null) { for (SCM scm : item.getSCMs()) { if (scm instanceof GitSCM) { return (GitSCM) scm; } } } return null; }
Example #7
Source File: ProjectLabelsProvider.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
/** * Get the URL of the first declared repository in the project configuration. * Use this as default source repository url. * * @return URIish the default value of the source repository url * @throws IllegalStateException Project does not use git scm. */ private URIish getSourceRepoURLDefault(Job<?, ?> job) { SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job); GitSCM gitSCM = getGitSCM(item); if (gitSCM == null) { LOGGER.log(Level.WARNING, "Could not find GitSCM for project. Project = {1}, next build = {2}", array(job.getName(), String.valueOf(job.getNextBuildNumber()))); throw new IllegalStateException("This project does not use git:" + job.getName()); } return getFirstRepoURL(gitSCM.getRepositories()); }
Example #8
Source File: ProjectLabelsProvider.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private GitSCM getGitSCM(SCMTriggerItem item) { if (item != null) { for (SCM scm : item.getSCMs()) { if (scm instanceof GitSCM) { return (GitSCM) scm; } } } return null; }
Example #9
Source File: ProjectBranchesProvider.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
/** * Get the URL of the first declared repository in the project configuration. * Use this as default source repository url. * * @return URIish the default value of the source repository url * @throws IllegalStateException Project does not use git scm. */ private URIish getSourceRepoURLDefault(Job<?, ?> job) { SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job); GitSCM gitSCM = getGitSCM(item); if (gitSCM == null) { LOGGER.log(Level.WARNING, "Could not find GitSCM for project. Project = {1}, next build = {2}", array(job.getName(), String.valueOf(job.getNextBuildNumber()))); throw new IllegalStateException("This project does not use git:" + job.getName()); } return getFirstRepoURL(gitSCM.getRepositories()); }
Example #10
Source File: ProjectBranchesProvider.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private GitSCM getGitSCM(SCMTriggerItem item) { if (item != null) { for (SCM scm : item.getSCMs()) { if (scm instanceof GitSCM) { return (GitSCM) scm; } } } return null; }
Example #11
Source File: GogsTrigger.java From gogs-webhook-plugin with MIT License | 4 votes |
@Override public boolean isApplicable(Item item) { return item instanceof Job && SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(item) != null && item instanceof ParameterizedJobMixIn.ParameterizedJob; }
Example #12
Source File: GogsPayloadProcessor.java From gogs-webhook-plugin with MIT License | 4 votes |
public GogsResults triggerJobs(String jobName, String deliveryID) { SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM); GogsResults result = new GogsResults(); try { BuildableItem project = GogsUtils.find(jobName, BuildableItem.class); if (project != null) { GogsTrigger gTrigger = null; Cause cause = new GogsCause(deliveryID); if (project instanceof ParameterizedJobMixIn.ParameterizedJob) { ParameterizedJobMixIn.ParameterizedJob pJob = (ParameterizedJobMixIn.ParameterizedJob) project; for (Trigger trigger : pJob.getTriggers().values()) { if (trigger instanceof GogsTrigger) { gTrigger = (GogsTrigger) trigger; break; } } } if (gTrigger != null) { SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(project); GogsPayload gogsPayload = new GogsPayload(this.payload); if (item != null) { item.scheduleBuild2(0, gogsPayload); } } else { project.scheduleBuild(0, cause); } result.setMessage(String.format("Job '%s' is executed", jobName)); } else { String msg = String.format("Job '%s' is not defined in Jenkins", jobName); result.setStatus(404, msg); LOGGER.warning(msg); } } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); LOGGER.severe(sw.toString()); } finally { SecurityContextHolder.setContext(saveCtx); } return result; }
Example #13
Source File: GitHubTriggerDescriptor.java From github-integration-plugin with MIT License | 4 votes |
@Override public boolean isApplicable(Item item) { return item instanceof Job && nonNull(SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(item)) && item instanceof ParameterizedJobMixIn.ParameterizedJob; }