本文整理汇总了Java中hudson.model.Queue.getItems方法的典型用法代码示例。如果您正苦于以下问题:Java Queue.getItems方法的具体用法?Java Queue.getItems怎么用?Java Queue.getItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hudson.model.Queue
的用法示例。
在下文中一共展示了Queue.getItems方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doEndOfflineAgentJobs
import hudson.model.Queue; //导入方法依赖的package包/类
public void doEndOfflineAgentJobs(final StaplerRequest request, final StaplerResponse response) {
Jenkins j;
if ((j = Jenkins.getInstance()) != null) {
Queue queue = j.getQueue();
if (queue != null) {
for (Item job : queue.getItems()) {
if (job.getCauseOfBlockage() instanceof BecauseNodeIsOffline
|| job.getCauseOfBlockage() instanceof BecauseLabelIsOffline) {
queue.cancel(job);
}
}
}
}
try {
response.sendRedirect2(request.getRootPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例2: cancelQueuedBuild
import hudson.model.Queue; //导入方法依赖的package包/类
@SuppressFBWarnings("SE_BAD_FIELD")
public static boolean cancelQueuedBuild(WorkflowJob job, Build build) {
String buildUid = build.getMetadata().getUid();
final Queue buildQueue = Jenkins.getActiveInstance().getQueue();
for (final Queue.Item item : buildQueue.getItems()) {
for (Cause cause : item.getCauses()) {
if (cause instanceof BuildCause && ((BuildCause) cause).getUid().equals(buildUid)) {
return ACL.impersonate(ACL.SYSTEM, new NotReallyRoleSensitiveCallable<Boolean, RuntimeException>() {
@Override
public Boolean call() throws RuntimeException {
buildQueue.cancel(item);
return true;
}
});
}
}
}
return cancelNotYetStartedBuild(job, build);
}
示例3: cancelSubBuilds
import hudson.model.Queue; //导入方法依赖的package包/类
public void cancelSubBuilds(final PrintStream logger) {
final Queue q = getJenkins().getQueue();
synchronized (q) {
final int n = this.dynamicBuild.getNumber();
for (final Item i : q.getItems()) {
final ParentBuildAction parentBuildAction = i.getAction(ParentBuildAction.class);
if (parentBuildAction != null && this.dynamicBuild.equals(parentBuildAction.getParent())) {
q.cancel(i);
}
}
for (final DynamicSubProject c : this.dynamicBuild.getAllSubProjects()) {
final DynamicSubBuild b = c.getBuildByNumber(n);
if (b != null && b.isBuilding()) {
final Executor exe = b.getExecutor();
if (exe != null) {
logger.println(Messages.MatrixBuild_Interrupting(ModelHyperlinkNote.encodeTo(b)));
exe.interrupt();
}
}
}
}
}
示例4: cancelQueuedBuilds
import hudson.model.Queue; //导入方法依赖的package包/类
public static void cancelQueuedBuilds(WorkflowJob job, String bcUid) {
Queue buildQueue = Jenkins.getActiveInstance().getQueue();
for (Queue.Item item : buildQueue.getItems()) {
for (Cause cause : item.getCauses()) {
if (cause instanceof BuildCause) {
BuildCause buildCause = (BuildCause) cause;
if (buildCause.getBuildConfigUid().equals(bcUid)) {
Build build = new BuildBuilder().withNewMetadata().withNamespace(buildCause.getNamespace())
.withName(buildCause.getName()).and().build();
cancelQueuedBuild(job, build);
}
}
}
}
}
示例5: createJenkinsModel
import hudson.model.Queue; //导入方法依赖的package包/类
public static JenkinsModel createJenkinsModel(Jenkins jenkins) {
Queue queue = jenkins.getQueue();
final Queue.Item[] items = queue.getItems();
int queueLength = items.length;
long maxwait = 0, averagewait = 0, now = System.currentTimeMillis();
for(Queue.Item item : items){
long waiting = now - item.getInQueueSince();
maxwait = maxwait > waiting ? maxwait : waiting;
averagewait += waiting;
}
if (queueLength > 0 ) {
averagewait = averagewait / queueLength;
}
QueueModel queueModel = new QueueModel(queueLength,queueLength - queue.countBuildableItems(), maxwait, averagewait);
int numFreeExecutors=0;
for (Computer computer : jenkins.getComputers()) {
if (computer.isOnline()){
numFreeExecutors += computer.countIdle();
}
}
SlaveModel slaveModel = new SlaveModel(jenkins.getComputers().length - 1, jenkins.getNumExecutors(), numFreeExecutors);
return new JenkinsModel(queueModel, slaveModel, jenkins.getDescription());
}
示例6: cancelPreviousJobsInQueueThatMatch
import hudson.model.Queue; //导入方法依赖的package包/类
private void cancelPreviousJobsInQueueThatMatch(@Nonnull BitbucketCause bitbucketCause) {
logger.fine("Looking for queued jobs that match PR ID: " + bitbucketCause.getPullRequestId());
Queue queue = getInstance().getQueue();
for (Queue.Item item : queue.getItems()) {
if (hasCauseFromTheSamePullRequest(item.getCauses(), bitbucketCause)) {
logger.fine("Canceling item in queue: " + item);
queue.cancel(item);
}
}
}
示例7: getQueueItem
import hudson.model.Queue; //导入方法依赖的package包/类
@Override
public synchronized Item getQueueItem() {
final Queue queue = Jenkins.getInstance().getQueue();
final Item[] items = queue.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i].task != null && items[i].task.equals(this)) {
return items[i];
}
}
return super.getQueueItem();
}
示例8: cancelQueuedBuildByPrNumber
import hudson.model.Queue; //导入方法依赖的package包/类
/**
* Cancel previous builds for specified PR id.
*/
public int cancelQueuedBuildByPrNumber(final int id) {
int canceled = 0;
SecurityContext old = impersonate(ACL.SYSTEM);
try {
final Queue queue = getJenkinsInstance().getQueue();
final Queue.Item[] items = queue.getItems();
//todo replace with stream?
for (Queue.Item item : items) {
if (!(item.task instanceof Job)) {
LOGGER.debug("Item {} not instanceof job", item);
continue;
}
final Job<?, ?> jobTask = (Job<?, ?>) item.task;
if (!jobTask.getFullName().equals(job.getFullName())) {
LOGGER.debug("{} != {}", jobTask.getFullName(), job.getFullName());
continue;
}
final CauseAction action = item.getAction(CauseAction.class);
if (isNull(action)) {
LOGGER.debug("Cause action is null for {}", jobTask.getFullName());
continue;
}
Optional<Cause> cause = from(action.getCauses())
.filter(instanceOf(GitHubPRCause.class))
.firstMatch(new CauseHasPRNum(id));
if (cause.isPresent()) {
LOGGER.debug("Cancelling {}", item);
queue.cancel(item);
canceled++;
}
}
} finally {
SecurityContextHolder.setContext(old);
}
return canceled;
}