How do I clear my Jenkins/Hudson build history?

后端 未结 14 1639
醉话见心
醉话见心 2020-12-07 08:10

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

相关标签:
14条回答
  • 2020-12-07 08:32

    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:

    def projectName = "ProjectName"
    def project = Jenkins.instance.getItem(projectName)
    def jobs = project.getItems().each {
      def job = it
      job.getBuilds().each { it.delete() }
      job.nextBuildNumber = 1
      job.save()
    }
    
    0 讨论(0)
  • 2020-12-07 08:32

    If using the Script Console method then try using the following instead to take into account if jobs are being grouped into folder containers.

    def jobName = "Your Job Name"
    def job = Jenkins.instance.getItemByFullName(jobName)
    

    or

    def jobName = "My Folder/Your Job Name
    def job = Jenkins.instance.getItemByFullName(jobName)
    
    0 讨论(0)
  • 2020-12-07 08:33

    This one is the best option available.

    Jenkins.instance.getAllItems(AbstractProject.class).each {it -> Jenkins.instance.getItemByFullName(it.fullName).builds.findAll { it.number > 0 }.each { it.delete() } }
    

    This code will delete all Jenkins Job build history.

    0 讨论(0)
  • 2020-12-07 08:35

    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

    0 讨论(0)
  • 2020-12-07 08:37

    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.

    0 讨论(0)
  • 2020-12-07 08:37

    Using Script Console.

    In case the jobs are grouped it's possible to either give it a full name with forward slashes:

    getItemByFullName("folder_name/job_name") 
    job.getBuilds().each { it.delete() }
    job.nextBuildNumber = 1
    job.save()
    

    or traverse the hierarchy like this:

    def folder = Jenkins.instance.getItem("folder_name")
    def job = folder.getItem("job_name")
    job.getBuilds().each { it.delete() }
    job.nextBuildNumber = 1
    job.save()
    
    0 讨论(0)
提交回复
热议问题