How do I clear my Jenkins/Hudson build history?

后端 未结 14 1638
醉话见心
醉话见心 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:39

    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):

    // change this variable to match the name of the job whose builds you want to delete
    def jobName = "Your Job Name"
    def job = Jenkins.instance.getItem(jobName)
    
    job.getBuilds().each { it.delete() }
    // uncomment these lines to reset the build number to 1:
    //job.nextBuildNumber = 1
    //job.save()
    
    0 讨论(0)
  • 2020-12-07 08:39

    Here is another option: delete the builds with cURL.

    $ curl -X POST http://jenkins-host.tld:8080/jenkins/job/myJob/[1-56]/doDeleteAll
    

    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:

    $ curl -u userName:apiToken -X POST http://jenkins-host.tld:8080/jenkins/job/myJob/[1-56]/doDeleteAll
    

    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 by doDelete in the URLs above to make this work, depending on the configuration or the version of Jenkins used.

    0 讨论(0)
提交回复
热议问题