我是 Groovy 和 jenkins 的新手,我正在编写一个脚本,以使用 groovy 脚本仅从 Git 构建已提交的脚本。 我收到以下错误
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'OMX_Automation_git_2104 #18' with class 'hudson.maven.MavenModuleSetBuild' to class 'hudson.model.Build'
我使用的脚本如下
import hudson.model.Build
import hudson.model.Result
import hudson.scm.ChangeLogSet
import hudson.scm.SubversionChangeLogSet.LogEntry
logLevelDebug = false // log debug
encoding = "ISO-8859-1" // Latin-1
out = getBinding().getVariables()['out']
def log(msg) {
out.println("[jenkins] ${msg}")
}
def debugLog(msg) {
if (logLevelDebug) {
log("DEBUG: ${msg}")
}
}
def changedFiles() {
def Build build = Thread.currentThread()?.executable
def ListchangedFiles = changedFileSinceLastSuccessfull(build)
changedFiles.unique().sort()
}
def changedFileSinceLastSuccessfull(Build build) {
if (build == null || build.result == Result.SUCCESS) {
debugLog("Stopping at build '${build}' which was successful (or empty)")
[]
} else {
log("Collecting changes of build '${build}'")
changedFilesIn(build) + changedFileSinceLastSuccessfull(build.getPreviousBuild())
}
}
def changedFilesIn(Build build) {
def ChangeLogSetchangeSet = build.getChangeSet()`enter code here`
def ListchangedItems = changeSet.getItems()
debugLog("${changedItems.size()} changed items")
def changedPaths = changedItems.collect { logEntry -> logEntry.paths }.flatten()
debugLog("${changedPaths.size()} changed paths")
def changedFiles = changedPaths.collect { path -> path.path }
debugLog("${changedFiles.size()} changed files")
changedFiles
}
def save(ListfileNames) {
def File lstFile = new File("${workspace()}/changed_files.log")
log("Saving list of files names to ${lstFile}")
lstFile.withWriter(encoding){ file ->
fileNames.each { name -> file.println name }
}
}
def workspace() {
def Build build = Thread.currentThread()?.executable
build.getWorkspace().toString()
}
log('Collecting changes files')
save(changedFiles())