如何清除我的 Jenkins/Hudson 构建历史记录?
我最近更新了我的哈德森构建之一的配置。构建历史记录不同步。有没有办法清除我的构建历史记录?
请并谢谢你
I recently updated the configuration of one of my hudson builds. The build history is out of sync. Is there a way to clear my build history?
Please and thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
使用脚本控制台(管理 Jenkins > 脚本控制台)和类似此脚本的内容来批量删除作业的构建历史记录 https://github.com/jenkinsci/jenkins-scripts/blob/master/scriptler/bulkDeleteBuilds.groovy
该脚本假设您只想删除一系列构建。要删除给定作业的所有构建,请使用此命令(已测试):
Use the script console (Manage Jenkins > Script Console) and something like this script to bulk delete a job's build history https://github.com/jenkinsci/jenkins-scripts/blob/master/scriptler/bulkDeleteBuilds.groovy
That script assumes you want to only delete a range of builds. To delete all builds for a given job, use this (tested):
此答案适用于 Jenkins
转到 Jenkins 主页 → 管理 Jenkins → 脚本控制台
在那里运行以下脚本。将
copy_folder
更改为您的项目名称
代码:
我的帖子
This answer is for Jenkins
Go to your Jenkins home page → Manage Jenkins → Script Console
Run the following script there. Change
copy_folder
toyour project name
Code:
My post
如果您单击管理 Hudson / 从磁盘重新加载配置,Hudson 将重新加载所有构建历史数据。
如果磁盘上的数据混乱,您需要转到 %HUDSON_HOME%\jobs\<projectname>目录并恢复构建目录,因为它们应该是。然后重新加载配置数据。
如果您只是询问如何删除所有构建历史记录,则可以通过 UI 将构建一一删除(如果只有少数),或者转到 %HUDSON_HOME%\jobs\<projectname>目录并删除那里的所有子目录——它们对应于构建。
然后重新启动服务以使更改生效。
If you click Manage Hudson / Reload Configuration From Disk, Hudson will reload all the build history data.
If the data on disk is messed up, you'll need to go to your %HUDSON_HOME%\jobs\<projectname> directory and restore the build directories as they're supposed to be. Then reload config data.
If you're simply asking how to remove all build history, you can just delete the builds one by one via the UI if there are just a few, or go to the %HUDSON_HOME%\jobs\<projectname> directory and delete all the subdirectories there -- they correspond to the builds.
Afterwards restart the service for the changes to take effect.
这是另一个选项:使用 cURL 删除构建。
上面删除了作业 myJob 的构建 #1 到 #56。
如果在 Jenkins 实例上启用了身份验证,则必须提供用户名和 API 令牌,如下所示:
必须从 Jenkins 中的
/me/configure
页面获取 API 令牌。只需单击“显示 API 令牌...”按钮即可显示用户名和 API 令牌。编辑:可能需要将上面 URL 中的
doDeleteAll
替换为doDelete
才能完成此操作,具体取决于所使用的 Jenkins 的配置或版本。Here is another option: delete the builds with cURL.
The above deletes build #1 to #56 for job myJob.
If authentication is enabled on the Jenkins instance, a user name and API token must be provided like this:
The API token must be fetched from the
/me/configure
page in Jenkins. Just click on the "Show API Token..." button to display both the user name and the API token.Edit: one might have to replace
doDeleteAll
bydoDelete
in the URLs above to make this work, depending on the configuration or the version of Jenkins used.以下是如何使用 Jenkins 脚本删除所有作业的所有构建......。
Here is how to delete ALL BUILDS FOR ALL JOBS...... using the Jenkins Scripting.
您可以临时修改项目配置以仅保存最后 1 个构建,重新加载配置(这应该废弃旧的构建),然后再次将配置设置更改为您想要的值。
You could modify the project configuration temporarily to save only the last 1 build, reload the configuration (which should trash the old builds), then change the configuration setting again to your desired value.
这是可用的最佳选择。
此代码将删除所有 Jenkins 作业构建历史记录。
This one is the best option available.
This code will delete all Jenkins Job build history.
如果你想清除MultiBranchProject的构建历史(例如管道),
转到 Jenkins 主页 → 管理 Jenkins → 脚本控制台并运行以下脚本:
If you want to clear the build history of MultiBranchProject (e.g. pipeline),
go to your Jenkins home page → Manage Jenkins → Script Console and run the following script:
使用脚本控制台。
如果作业被分组,可以给它一个带有正斜杠的全名:
或者像这样遍历层次结构:
Using Script Console.
In case the jobs are grouped it's possible to either give it a full name with forward slashes:
or traverse the hierarchy like this:
直接从文件系统删除并不安全。您可以运行以下脚本来删除所有作业中的所有构建(递归地)。
Deleting directly from file system is not safe. You can run the below script to delete all builds from all jobs ( recursively ).
转到“管理詹金斯”> “脚本控制台”
运行如下:
Go to "Manage Jenkins" > "Script Console"
Run below:
清理构建的另一种简单方法是在作业结束时添加“丢弃旧插件”。设置要保存的最大构建数,然后再次运行作业:
https://wiki.jenkins-ci.org/display/JENKINS/Discard+Old+Build+plugin
Another easy way to clean builds is by adding the Discard Old Plugin at the end of your jobs. Set a maximum number of builds to save and then run the job again:
https://wiki.jenkins-ci.org/display/JENKINS/Discard+Old+Build+plugin
转到
%HUDSON_HOME%\jobs\
删除builds
目录并删除lastStable、lastSuccessful
链接,然后删除nextBuildNumber
文件。完成上述步骤后,从 UI 转到以下链接
詹金斯->管理 Jenkins ->从磁盘重新加载配置
它将根据您的需要进行
Go to the
%HUDSON_HOME%\jobs\<projectname>
removebuilds
dir and removelastStable, lastSuccessful
links, and removenextBuildNumber
file.After doing above steps go to below link from UI
Jenkins-> Manage Jenkins -> Reload Configuration from Disk
It will do as you need
如果使用脚本控制台方法,请尝试使用以下方法来考虑作业是否分组到文件夹容器中。
或者
If using the Script Console method then try using the following instead to take into account if jobs are being grouped into folder containers.
or
导航至:
%JENKINS_HOME%\jobs\jobName
打开文件“nextBuildNumber”并更改数字。之后重新加载 Jenkins 配置。注意:“nextBuildNumber”文件包含 Jenkins 将使用的下一个版本号。
Navigate to:
%JENKINS_HOME%\jobs\jobName
Open the file "nextBuildNumber" and change the number. After that reload Jenkins configuration. Note: "nextBuildNumber" file contains the next build no that will be used by Jenkins.
在 Linux 上的 jenkins 2.293 上进行了测试。它将删除所有构建日志,但不会删除相关构建号
请小心使用此命令,因为它会对每个查找结果执行rm -rf。您可以先执行此命令来验证结果是否仅在您作业的builds文件夹中
Tested on jenkins 2.293 over linux. It will remove all the build logs but not the corellative build number
Be careful with this command because it executes a rm -rf on each find result. You could exec this first to validate if the result are only the builds folder of you jobs
如果您正在寻找文件夹内有作业的解决方案,您可以使用
getItemByFullName
函数。它还支持文件夹和作业名称中的空格。If you are looking for a solution where you have job inside a Folder you can use
getItemByFullName
function. It also supports white space in folder and job name.转到 Jenkins 主页 → 管理 Jenkins → 脚本控制台
Go to your Jenkins home page → Manage Jenkins → Script Console