use of jenkins.triggers.SCMTriggerItem in project gogs-webhook-plugin by jenkinsci.
the class GogsPayloadProcessor method triggerJobs.
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;
}
use of jenkins.triggers.SCMTriggerItem in project sonar-scanner-jenkins by SonarSource.
the class BuilderUtils method getModuleRoot.
public static FilePath getModuleRoot(Run<?, ?> run, FilePath workspace) {
FilePath moduleRoot = null;
if (run instanceof AbstractBuild) {
AbstractBuild<?, ?> build = (AbstractBuild<?, ?>) run;
moduleRoot = build.getModuleRoot();
} else {
// otherwise get the first module of the first SCM
Object parent = run.getParent();
if (parent instanceof SCMTriggerItem) {
SCMTriggerItem scmTrigger = (SCMTriggerItem) parent;
Collection<? extends SCM> scms = scmTrigger.getSCMs();
if (!scms.isEmpty()) {
SCM scm = scms.iterator().next();
FilePath[] moduleRoots = scm.getModuleRoots(workspace, null);
moduleRoot = moduleRoots != null && moduleRoots.length > 0 ? moduleRoots[0] : null;
}
}
if (moduleRoot == null) {
moduleRoot = workspace;
}
}
return moduleRoot;
}
Aggregations