我想知道是否有可能删除由特定用户构建的旧构建?我知道我可以使用jenkins脚本控制台中的一个脚本,并按编号删除旧构建,但有没有办法按运行它们的人过滤它们?thnx!
huwehgph1#
您可以使用下面的Groovy脚本来实现这一点。为了安全起见,我已经注解掉了实际的delete行,并添加了println。请根据需要调整脚本。
def userNameToCheck="admin" Jenkins.instance.getAllItems(Job.class).each { jobitem -> def jobName = jobitem.name def jobInfo = Jenkins.instance.getItem(jobName) if(jobInfo.getLastBuild()){ def lastBuildNum=jobInfo.getLastBuild().getNumber() def deletedNumRange = Fingerprint.RangeSet.fromString("0-${lastBuildNum}",false); def buildCount=jobInfo.getBuilds(deletedNumRange).size() if(buildCount==0){ println("No build logs found in ${jobName} and build history count is : ${buildCount}") } else{ jobInfo.getBuilds(deletedNumRange).each { item -> // Check if the build was executed by the specified user if(item.getCause(Cause.UserIdCause).getUserId().equals(userNameToCheck)) { //item.delete() println("Deleting a Build. For JOB : " + jobName + " for user " + item.getCause(Cause.UserIdCause).getUserId()) } } } } else { println("No builds found in ${jobName}") } }
1条答案
按热度按时间huwehgph1#
您可以使用下面的Groovy脚本来实现这一点。为了安全起见,我已经注解掉了实际的delete行,并添加了println。请根据需要调整脚本。