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

Perforce管理内核代码,Jenkins编译时版本附加dirty串问题求助

Fixing "dirty" Kernel Version Tag in Jenkins Builds with Perforce

Hey there, let's figure out why that annoying "-dirty" tag is popping up in your Jenkins kernel builds—even after you've submitted all your changes via Perforce—and how to get rid of it.

Why This Happens

The Linux kernel's versioning logic (handled by scripts/setlocalversion) is Git-first by default. It checks for uncommitted changes in a Git repo to add the "dirty" tag. Since you're using Perforce instead, here's what's likely going wrong:

  • The kernel script is still trying to run Git checks in your Jenkins environment, either finding leftover Git artifacts or misinterpreting the Perforce workspace state as "dirty."
  • Your Jenkins workspace might have untracked files (like build temp files, or files not added to Perforce) that the script flags as uncommitted changes.
  • Perforce sync in Jenkins isn't fully cleaning up the workspace, leaving behind modified or unversioned files.

Solutions to Try

1. Override the "dirty" Check Directly

The quickest fix is to explicitly tell the build to skip the dirty tag by passing the LOCALVERSION variable when running make:

make LOCALVERSION="" <your-other-build-flags>

This forces the kernel to use an empty local version string, overriding any automatic "dirty" tag addition.

2. Tweak the scripts/setlocalversion Script for Perforce

If you want a permanent fix aligned with your Perforce workflow, modify the kernel's versioning script to check Perforce status instead of Git:

  1. Open scripts/setlocalversion in your kernel source.
  2. Find the Git-checking block (starts with if test -d .git && head=git rev-parse...`).
  3. Replace or supplement it with Perforce-specific logic:
# Check for Perforce workspace instead of Git
if p4 info >/dev/null 2>&1; then
    # Check if there are uncommitted changes or untracked files
    if p4 status | grep -E "(not opened|changed but not submitted)" >/dev/null 2>&1; then
        dirty="-dirty"
    else
        dirty=""
    fi
else
    # Fallback to original Git check if not in a Perforce workspace
    # (keep the original Git logic here if needed)
    dirty=""
fi

This will only add the "dirty" tag if Perforce detects uncommitted changes, matching your actual workflow.

3. Ensure Jenkins Workspace is Fully Clean

Make sure Jenkins starts with a pristine workspace every build:

  • Add a pre-build step to run p4 sync -f to force sync all files to the latest submitted version.
  • If your Perforce version supports it, run p4 clean to delete any untracked files in the workspace before building.
  • Enable Jenkins's workspace cleanup options or add a step to delete old build outputs to avoid leftover artifacts.

Testing the Fix

Before rolling out to your full pipeline:

  1. SSH into your Jenkins build agent and navigate to the kernel workspace.
  2. Run p4 status to confirm there are no uncommitted changes or untracked files.
  3. Test your modified build command (or script change) locally on the agent to verify the version string no longer has "-dirty".

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:16:53