면책 조항 : 나는 설명하려고 생각하는 것보다 더 좋은 방법이있을 수 있습니다 (이것은 손으로 무거운 것) 그러나 우리는 또한 내장 된 젠킨스 제외 설정 부족을 발견했다. 주로 트리거 된 빌드에만 적용 되었기 때문에 다중 분기 파이프 라인 검사가 예약되지 않았습니다. 또한 이것은 단지 에만 적용됩니다. Groovy DSL jobs; 프리 스타일 작업이나 선언적 파이프 라인 작업이 아닙니다.
베스트 내가 사용하는 구체적인 구현을 위해 의사에
if git changed files since last run == 0 then
no need to change puppetfile
end build
endif
if 1 file changed and it is puppetfile then
if the contents of the change is just the auto-changed puppetfile stuff
no need to change puppetfile again
end build
endif
endif
if we get here then more stuff changed so do the auto-change puppetfile stuff
세부
을 설명
요약 자바 스크립트 프로젝트의 package.json
예를 들어 있지만, 정확히 같은 상황입니다 puppetfile
. package.json
을 puppetfile
및 version:
으로 바꾸면 다른 빌드가 실행되지 않아야 자동으로 생성되는 내용이 변경됩니다.
/**
* Utility method to run git and handle splitting its output
*/
def git(command) {
def output = []
outputRaw = sh(
script: "git $command",
returnStdout: true
)
if (!outputRaw.empty) {
output = outputRaw.split('\n')
}
return output
}
/**
* The names of files changed since the last successful build
*/
def getFilesChangedSinceLastSuccessfulBuild() {
def filesChanged = []
if (lastSuccessfulCommit) {
filesChanged = git "diff --name-only $currentCommit '^$lastSuccessfulCommit'"
}
echo "DEBUG: Files changed $filesChanged (size ${filesChanged.size()})"
return filesChanged
}
/**
* Get changes as a list without context
*/
def getContextFreeChanges() {
def contentsChanged = []
if (lastSuccessfulCommit) {
contentsChanged = git "diff --unified=0 $lastSuccessfulCommit $currentCommit | egrep '^\\+ ' || exit 0"
}
echo "DEBUG: Contents changed: $contentsChanged (size ${contentsChanged.size()})"
return contentsChanged
}
그런 다음 우리가 그 걸릴 needToBumpVersion()
를 (적절한 이름 변경) 변경이 발생 할 필요가 자동 생성 어떤 밖으로 내기 위해 모두 함께 묶어하는 생성 :
먼저 우리는 몇 가지 유틸리티 메소드를 필요
/**
* Do we need to actually increment version in package.json
*/
def needToBumpVersion() {
def filesChanged = getFilesChangedSinceLastSuccessfulBuild()
if (filesChanged.size() == 0) {
echo "INFO: No files changed, no need to bump version"
return false
}
if (filesChanged.size() == 1 && filesChanged[0] == 'package.json') {
def contentsChanged = getContextFreeChanges()
if (contentsChanged.size() == 1 && contentsChanged[0] =~ /"version":/) {
echo "INFO: Don't need to bump version, it has already been done"
return false
}
}
echo "INFO: We do need to bump the version, more than just package.json version string changed"
return true
}
및 마침내 자동 생성을 변경할지 여부를 당신은 알아낼이 방법을 사용할 수 있습니다 및 커밋 :
을
if (needToBumpVersion()) {
// Do bump here
}
awesome! 이걸로 놀러 다니, 내가 일할 수 있는지. – jrich523