Perforce管理内核代码,Jenkins编译时版本附加dirty串问题求助
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:
- Open
scripts/setlocalversionin your kernel source. - Find the Git-checking block (starts with
if test -d .git && head=git rev-parse...`). - 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 -fto force sync all files to the latest submitted version. - If your Perforce version supports it, run
p4 cleanto 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:
- SSH into your Jenkins build agent and navigate to the kernel workspace.
- Run
p4 statusto confirm there are no uncommitted changes or untracked files. - 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

