我是 Jenkins 和 Groovy 的新手。我需要能够检测是否添加或删除了签入 Jenkins 的文件。但是,我似乎无法构造类权限来返回编辑值。
Changeset.Item 类的链接在这里
我尝试使用的代码是:
import java.lang.*
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
import hudson.util.*
import hudson.scm.*
import hudson.scm.SubversionChangeLogSet.LogEntry
import com.microsoft.tfs.core.clients.versioncontrol.specs.version.ChangesetVersionSpec
import hudson.model.User
import hudson.plugins.tfs.commands.RemoteChangesetVersionCommand
import hudson.plugins.tfs.model.ChangeSet.Item
import groovy.util.slurpersupport.GPathResult
import groovy.xml.XmlUtil
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.MarkupBuilder
import java.io.Serializable
import java.lang.Cloneable
// work with current build
def build = Thread.currentThread()?.executable
// get ChangesSets with all changed items
def changeSet = build.getChangeSet()
def items = changeSet.getItems()
println "Affected Paths"
def affectedFiles = items.collect {
it.getAffectedPaths()
}
println affectedFiles
Item typeItems = items
def kind = typeItems .collect {
it.getEditType()
}
println kind
我得到的错误是:
08:49:00 ERROR: Build step failed with exception
08:49:00 org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[Ljava.lang.Object;@11890e4' with class '[Ljava.lang.Object;' to class 'hudson.plugins.tfs.model.ChangeSet$Item' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: hudson.plugins.tfs.model.ChangeSet$Item(hudson.plugins.tfs.model.ChangeSet)
08:49:00 at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:403)
08:49:00 at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
08:49:00 at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
08:49:00 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
08:49:00 at Script1.run(Script1.groovy:38)
08:49:00 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
08:49:00 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
08:49:00 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
08:49:00 at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:343)
08:49:00 at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:95)
08:49:00 at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:59)
08:49:00 at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
08:49:00 at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
08:49:00 at hudson.model.Build$BuildExecution.build(Build.java:206)
08:49:00 at hudson.model.Build$BuildExecution.doRun(Build.java:163)
08:49:00 at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
08:49:00 at hudson.model.Run.execute(Run.java:1727)
08:49:00 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
08:49:00 at hudson.model.ResourceController.execute(ResourceController.java:97)
08:49:00 at hudson.model.Executor.run(Executor.java:429)
08:49:00 Build step 'Execute system Groovy script' marked build as failure
我相信这是一个非常容易解决的问题。我尝试了很多不同的方法,似乎离解决方案越来越远。