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

如何仅禁用Jenkins中“Pipeline from SCM”的轮询功能?

Jenkins Pipeline任务异常触发问题:GitHub仓库变更误触发构建

场景与问题

常规Pipeline任务配置如下:

  • 使用Pipeline from SCM(GitHub仓库存储Jenkinsfile),已启用Lightweight checkout
  • 流水线依赖GitHub共享库,实际项目代码通过RTC检出
  • 需求:仅RTC项目变更触发构建,GitHub仓库的变更不应触发

此前配置正常运行数月,符合Lightweight checkout“不基于该SCM生成变更日志或执行轮询”的特性,但近期Jenkins开始检测GitHub仓库变更并持续触发构建,且无法通过路径排除规则阻止。

已尝试无效操作

  • 添加Additional Behaviours -> Polling ignores commits in certain paths,设置Excluded Regions为.*,Included Regions为不存在的文件名
  • 复制任务后新任务轮询正常,但原任务问题依旧

关键日志

原任务异常轮询日志

Started on Nov 10, 2023, 9:58:00 PM
Using strategy: Default
[poll] Last Built Revision: Revision 5c4406e529101df3cc8cb3aef212f3decf0c96ea (origin/85-updates-in-this-repository-are-triggering-myproj-sw-builds-in-jenkins)
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
using credential localuser-github-personal-access-token
 > git --version # timeout=10
 > git --version # 'git version 2.39.2'
using GIT_ASKPASS to set credentials localuser's Personal Access Token at GitHub (DO NOT DELETE; DO NOT UPDATE)
Setting http proxy: proxy-sl.temp.com:8080
 > git ls-remote -h -- https://github.tempdevcloud.com/bios-tools/myproj-gradle-project.git # timeout=10
Found 9 remote heads on https://github.tempdevcloud.com/bios-tools/myproj-gradle-project.git
[poll] Latest remote head revision on refs/heads/main is: 643e37aa70614544bff50a0e7641f4ab3dc96e2f
RTC : checking for changes...
Determining if there are incoming changes using the build toolkit
Checking incoming changes for "myproj_Platform_Dev_CITeam"
Reusing facade for /var/jenkins_home/tools/com.ibm.team.build.internal.hjplugin.RTCBuildToolInstallation/RTC_Build_Toolkit_7.0.2-20220301_temp_fix/RCM-EWM-BuildSystem-Toolkit-Win64-7.0.2-202203010930-FINALGA/buildsystem/buildtoolkit
RTC : No changes detected
Done. Took 2.7 sec
Changes found

复制任务正常轮询日志

Started on Nov 10, 2023, 10:14:00 PM
no polling baseline in /var/jenkins_home/workspace/rar6si/test-stpid-polling-in-loop@libs/ba472398708df440adf10397fd167023c27c2ddec78fa7f630bc7a43d116b64a on 
Done. Took 0 ms
No changes

有效解决方法

1. 重置任务的轮询基线

原任务的轮询基线可能被错误缓存,导致持续检测到GitHub仓库的“变更”:

  • 方法A:修改任务配置文件
    找到Jenkins任务的配置文件(路径:${JENKINS_HOME}/jobs/[你的任务名]/config.xml),搜索<scm>节点下的<pollingBaseline>或<lastBuiltRevision>相关内容,将其值替换为GitHub仓库当前最新的提交哈希(即日志中的643e37aa70614544bff50a0e7641f4ab3dc96e2f),保存后重启Jenkins或重新加载任务配置。

  • 方法B:通过脚本控制台执行
    进入Jenkins的Manage Jenkins -> Script Console,执行以下Groovy脚本(替换任务名和最新提交哈希):

    def job = Jenkins.instance.getItemByFullName("你的任务全称")
    def scm = job.scm
    if (scm) {
      def poller = scm.getPoller(job)
      // 重置基线到最新GitHub提交
      poller.setLastPollBaseline(job, null, "643e37aa70614544bff50a0e7641f4ab3dc96e2f")
      job.save()
      println "轮询基线已重置"
    } else {
      println "未找到任务的SCM配置"
    }
    

2. 调整触发器配置,仅保留RTC触发

  • 在任务配置的Build Triggers中,取消勾选Poll SCM选项
  • 添加RTC插件提供的专属变更触发器(如果支持),或使用Cron表达式配合自定义脚本,仅在检测到RTC变更时触发构建

3. 重构Jenkinsfile,跳过默认SCM检出

在Jenkinsfile中明确跳过默认的GitHub SCM检出,手动控制RTC代码拉取:

pipeline {
  agent any
  options {
    skipDefaultCheckout() // 跳过默认的GitHub仓库检出
    disableConcurrentBuilds()
  }
  triggers {
    // 仅配置RTC相关触发器,例如:
    // rtc(...) // 需根据RTC插件语法配置
    // 或使用Cron+自定义变更检查脚本
  }
  stages {
    stage('Checkout RTC Code') {
      steps {
        // 手动执行RTC代码检出步骤,例如使用RTC插件或命令行
        rtcCheckout(...)
      }
    }
    // 后续构建阶段
  }
}

4. 清理任务缓存与工作区

  • 删除任务的工作区目录:${JENKINS_HOME}/workspace/[你的任务名]
  • 删除任务的共享库缓存目录:${JENKINS_HOME}/workspace/[你的任务名]@libs
  • 触发一次手动构建后,重新开启轮询

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 20:24:51