Programing

젠킨스에서 빌드 번호를 재설정하는 방법은 무엇입니까?

crosscheck 2020. 10. 11. 09:09
반응형

젠킨스에서 빌드 번호를 재설정하는 방법은 무엇입니까?


Jenkins와 Gradle을 사용하여 Java 프로젝트를 빌드하고 있습니다.

프로젝트를 빌드 할 때마다 Jenkins 화면에 새 빌드 번호가 표시됩니다.

다음은 내 Jenkins 빌드 정보입니다.

Success > Console Output  #96   03-Jan-2014 15:35:08    
Success > Console Output  #95   03-Jan-2014 15:27:29     
Failed > Console Output  #94    03-Jan-2014 15:26:16     
Failed > Console Output  #93    03-Jan-2014 15:25:01     
Failed > Console Output  #92    03-Jan-2014 15:23:50     
Success > Console Output  #91   03-Jan-2014 12:42:32    
Success > Console Output  #90   03-Jan-2014 12:02:45

Jenkins 빌드 번호를 다음과 같이 재설정하고 싶습니다.

Success > Console Output  #1    03-Jan-2014 12:02:45

Jenkins에서 빌드 번호를 어떻게 재설정 할 수 있습니까?

미리 감사드립니다.


그루비 스크립트 콘솔에서 더 쉽게 할 수 있습니다. 로 이동하여 HTTP : 당신의-젠킨스 서버 / 스크립트 // 스크립트 창에서 입력 :

item = Jenkins.instance.getItemByFullName("your-job-name-here")
//THIS WILL REMOVE ALL BUILD HISTORY
item.builds.each() { build ->
  build.delete()
}
item.updateNextBuildNumber(1)

에서 여기

Hudson 작업 이름이 FooBar 인 경우

  • FooBar를 FooBar-Copy로 이름 변경
  • FooBar-Copy에서 '기존 작업 복사'옵션을 사용하여 FooBar라는 새 작업을 만듭니다.
  • FooBar-Copy 삭제

  • 먼저 작업 공간을 정리하고 이전 빌드를 제거합니다.
    • 서버에서 작업 디렉토리로 이동하십시오. 'var / lib / jenkins / jobs / myJob'작업 공간 및 빌드 디렉토리와 폴링 파일, lastSuccessful, lastStable 파일 등을 삭제합니다. config.xml 및 lastBuildNumber 만 있어야합니다.
    • 서비스 젠킨스 중지 와 같은 것을 사용하여 젠킨스 종료
    • nextBuildNumber 라는 파일을 편집하고 현재 빌드 번호 대신 1을 삽입합니다.
    • 젠킨스를 다시 시작하고 젠킨스 서비스를 시작하세요
    • 젠킨스에 로그인하고 작업으로 이동하여 빌드를 누르십시오. 작업 # 1 구축을 시작해야합니다.

다음 빌드 번호를 설정하려면 "NextBuildNumber"플러그인이 있습니다. 그러나 필요한 빌드 번호 인 1이 현재 빌드 번호보다 적기 때문에 귀하의 경우에는 작동하지 않습니다.

먼저 이전 빌드를 모두 삭제해야합니다. 이 간단한 스크립트를 실행하여 수행 할 수 있습니다 .-> Jenkins 관리-> 스크립트 콘솔로 이동하십시오.

// 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() }

이제 다음 빌드 번호를 1로 설정하고 빌드를 실행할 수 있습니다. 1로 시작 합니다. :) 간단합니다.

업데이트-Jenkins에는 이제 작업 기록 제거 플러그인이있어이 작업을 가장 쉽게 수행 할 수 있습니다. 자세한 내용은 페이지에서 확인하세요-https: //wiki.jenkins.io/display/JENKINS/Purge+Job+History+Plugin


일반적으로 빌드 번호를 다음으로 재설정하려면 N( N반드시 1 일 필요는 없음) :

  • 기존의 위치를 기반으로 삭제합니다 buildNumber >= N.
  • 편집 Program Files (x86)/Jenkins/jobs/yourjob/nextBuildNumber. 포함 된 번호를로 설정합니다 N.
  • Jenkins에서 Manage Jenkins -> Reload Configuration from Disk.

허용되는 답변을 확장하여 모든 프로젝트에 대해 한 번에 수행하는 방법은 다음과 같습니다.

Jenkins.instance.allItems.each() { 
  item -> item.builds.each() { 
    build -> build.delete()
  }
  item.updateNextBuildNumber(1)
}  

@antweiss의 탁월한 답변의 확장으로 실제로 더 나아갈 수 있습니다 ...

전체 빌드 기록을 삭제할 필요가 없습니다. 원하지 않는 경우 이전 시점으로 시간을 간단히 롤백 할 수 있습니다.

resetNumberTarget = 14
item = Jenkins.instance.getItemByFullName("Project Name [from project Dashboard]")
//println(item)

item.builds.each() { build ->
  //println(build)
  //println(build.number)

  if(build.number >= resetNumberTarget)
  {
    //println("About to Delete '" + build + "'")    
    build.delete()  
  }
}

item.updateNextBuildNumber(resetNumberTarget)

더미 실행을 원하는 경우 실제로 수행하지 않고 수행 할 작업을 확인하려면 build.delete()item.updateNextBuildNumber(resetNumberTarget)줄을 주석 처리하고 다양한 인쇄 명령의 주석 처리를 제거하면됩니다.


문서 : 이러한 개체의 세부 정보를 찾기가 어려웠지만 다음을 확인했습니다.


You can use either nexBuildNumber plug-in or simply modify nexBuildNumber file to reset build number. Following are the steps that you need to perform:

  • Go to .jenkins/Jobs/<YourJobName>/build/, take backup of this folder(if you need for future use) and delete build folder.

Note: Once you clean up old builds, you lose build histories and they are no longer available on the Jenkins dashboard.

  • Reload the configuration(Jenkins -> Manage Jenkins).
  • Set next build version to 1 by either using the Next Build Number plug-in or modifying the nextBuildNumber file in yourjob directory.

I found an easy way to do this.

  1. Wipe out your work space.
  2. Go to each builds which saved on Jenkins and delete it.
  3. Set build number to 1 then build.

Jenkins use previous build to determine the next build number, if build number you input is lower than previous build number, Jenkins will automatically increase your build number to higher than previous build. So here we just


To reset build numbers of all jobs:

Jenkins.instance.getAllItems(AbstractProject.class).each {
    item = Jenkins.instance.getItemByFullName(it.fullName)
    //THIS WILL REMOVE ALL BUILD HISTORY
    item.builds.each() { build ->
        build.delete()
    }
    item.updateNextBuildNumber(1)
}

참고URL : https://stackoverflow.com/questions/20901791/how-to-reset-build-number-in-jenkins

반응형