use of hudson.model.BuildableItem 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 hudson.model.BuildableItem in project blueocean-plugin by jenkinsci.
the class QueueContainerImpl method getQueuedItems.
/**
* This function gets gets a list of all queued items if the job is a buildable item.
*
* Note the estimated build number calculation is a guess - job types need not return
* sequential build numbers.
*
* @return List of items newest first
*/
public static List<BlueQueueItem> getQueuedItems(Job job) {
Link pipelineLink = LinkResolver.resolveLink(job);
if (job instanceof BuildableItem) {
BuildableItem task = (BuildableItem) job;
List<Queue.Item> items = Jenkins.getInstance().getQueue().getItems(task);
List<BlueQueueItem> items2 = Lists.newArrayList();
for (int i = 0; i < items.size(); i++) {
Link self = pipelineLink.rel("queue").rel(Long.toString(items.get(i).getId()));
items2.add(0, new QueueItemImpl(items.get(i), job.getName(), (items.size() == 1 ? job.getNextBuildNumber() : job.getNextBuildNumber() + i), self, pipelineLink));
}
return items2;
} else {
throw new ServiceException.UnexpectedErrorException("This pipeline is not buildable and therefore does not have a queue.");
}
}
use of hudson.model.BuildableItem in project blueocean-plugin by jenkinsci.
the class QueueUtil method getQueuedItems.
/**
* This function gets gets a list of all queued items if the job is a buildable item.
*
* Note the estimated build number calculation is a guess - job types need not return
* sequential build numbers.
*
* @return List of items newest first
*/
public static List<BlueQueueItem> getQueuedItems(BlueOrganization organization, Job job) {
BluePipeline pipeline = (BluePipeline) BluePipelineFactory.resolve(job);
if (job instanceof BuildableItem && pipeline != null) {
BuildableItem task = (BuildableItem) job;
List<hudson.model.Queue.Item> items = Jenkins.get().getQueue().getItems(task);
List<BlueQueueItem> items2 = new ArrayList<>();
for (int i = 0; i < items.size(); i++) {
Link self = pipeline.getLink().rel("queue").rel(Long.toString(items.get(i).getId()));
QueueItemImpl queueItem = new QueueItemImpl(organization, items.get(i), pipeline, (items.size() == 1 ? job.getNextBuildNumber() : job.getNextBuildNumber() + i), self, pipeline.getLink());
items2.add(0, queueItem);
}
return items2;
} else {
throw new ServiceException.UnexpectedErrorException("This pipeline is not buildable and therefore does not have a queue.");
}
}
Aggregations