You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在查看Jenkins编号任务日志时快速跳转到下一页

实现Jenkins任务日志页面快速切换到下一个编号任务

给你几个实用的自动化方案,不用再手动修改URL:

方法1:浏览器书签脚本(Bookmarklet)

无需安装插件,直接通过书签实现一键跳转:

  • 操作步骤:
    1. 在浏览器中新建书签,名称设为「Jenkins下一个任务」
    2. 将书签的URL替换为以下代码:
    javascript:(function(){const url = window.location.href;const match = url.match(/\/job\/([^\/]+)\/(\d+)\/console/);if(match){const nextUrl = url.replace(/\/(\d+)\/console/, `/${parseInt(match[2]) + 1}/console`);window.location.href = nextUrl;}else{alert('当前页面不是Jenkins任务日志页面');}})();
    
  • 使用方式:打开任意Jenkins任务日志页面,点击该书签即可自动跳转到下一个编号的任务日志页面。

方法2:Tampermonkey油猴脚本(自动添加切换按钮)

适合频繁使用的场景,脚本会在日志页面自动添加跳转按钮:

  1. 安装Tampermonkey浏览器插件
  2. 新建脚本,替换为以下代码(注意修改@match规则为你的Jenkins实例域名):
// ==UserScript==
// @name         Jenkins Next Job Console
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  快速跳转到下一个编号的Jenkins任务日志页面
// @author       You
// @match        http://{myJenkins-Instance}/job/*/*/console
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 创建跳转按钮
    const nextBtn = document.createElement('button');
    nextBtn.textContent = '下一个任务';
    nextBtn.style.cssText = 'padding:8px 16px; margin:10px; background:#4CAF50; color:white; border:none; border-radius:4px; cursor:pointer;';

    // 绑定跳转逻辑
    nextBtn.addEventListener('click', () => {
        const urlMatch = window.location.href.match(/\/job\/[^\/]+\/(\d+)\/console/);
        if(urlMatch){
            const nextNum = parseInt(urlMatch[1]) + 1;
            window.location.href = window.location.href.replace(/\/(\d+)\/console/, `/${nextNum}/console`);
        } else {
            alert('当前页面非Jenkins任务日志页面');
        }
    });

    // 将按钮插入页面顶部
    const header = document.querySelector('.page-header') || document.body;
    header.insertBefore(nextBtn, header.firstChild);
})();
  • 使用方式:打开Jenkins任务日志页面后,顶部会出现绿色的「下一个任务」按钮,点击即可跳转。

方法3:自定义键盘快捷键(需Jenkins管理员权限)

如果拥有Jenkins管理员权限,可以通过插件实现键盘快捷键跳转:

  1. 安装「Simple Theme Plugin」插件
  2. 在系统配置的「Theme」设置中,添加自定义JS代码,实现按下N键跳转下一个任务:
document.addEventListener('keydown', (e) => {
    if(e.key.toLowerCase() === 'n' && window.location.pathname.includes('/console')){
        const numMatch = window.location.pathname.match(/\/job\/[^\/]+\/(\d+)\/console/);
        if(numMatch){
            const nextNum = parseInt(numMatch[1]) + 1;
            window.location.href = window.location.href.replace(/\/(\d+)\/console/, `/${nextNum}/console`);
        }
    }
});

内容的提问来源于stack exchange,提问作者MBaas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 01:05:25