gpt4 book ai didi

Jenkins DSL 工作 : GroovyCastException Cannot cast object

转载 作者:行者123 更新时间:2023-12-02 02:48:52 25 4
gpt4 key购买 nike

我是 groovy 和 Jenkins DSL 工作的新手。我正在尝试使用常规脚本来创建运行测试脚本的作业。我遇到了一个 Cannot cast object 错误,我不确定问题是什么,也不确定是在什么地方放弃了转换。错误消息似乎没有指向特定的行,我认为这可能是类未导入的问题,但看起来确实如此。该错误似乎与 JenkinsDSL 文件有关。

下面是我创建的两个文件和错误消息。 JenkinsDSL.groovy 包含一个接收参数以创建作业的方法。

提前致谢!

更新我通过这个网站运行它:http://job-dsl.herokuapp.com/并确认问题出在 JenkinsDSL.groovy

JenkinsDSL.groovy

class JenkinsDSL {
String gitUrl, gitRemoteName, gitBranch, gitCredentials
String project, testSuite, testCaseName, testCaseDesc

def addJob(def dslFactory, String project, String testSuite, String testCaseName, String testCaseDesc) {

dslFactory.folder("Selenium Tests") {
displayName("Selenium Tests")
description("someDescription")
}

dslFactory.listView(project) {
description("Tests for ${project}")
filterBuildQueue()
filterExecutors()
jobs {
}
columns {
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
}
}

dslFactory.folder(testSuite) {
displayName(testSuite)
description("Verifies functionality related to ${testSuite}")
}

dslFactory.mavenJob("Selenium Tests/${project}/${testSuite}/${testCaseName}") {
description("${testCaseDesc}")
label('AWS-Linux-Java-7')
wrappers {
timeout {
absolute(5)
}
}
scm {
git {
remote {
name("${gitRemoteName}")
url("${gitUrl}")
credentials("${gitCredentials}")
}
branch("${gitBranch}")
}
}
parameters {
choiceParam('Browser', ['Chrome', 'Firefox', 'Safari'])
choiceParam('Environment', ['Dev', 'Test'])
choiceParam('TestCase', ["${testCaseName}"])
}
triggers {
parameterizedCron('''
H 0 * * * % Browser=Chrome;Environment=Dev;TestCase=TestCase
H 0 * * * % Browser=Firefox;Environment=Dev;TestCase=TestCase
H 0 * * * % Browser=Safari;Environment=Dev;TestCase=TestCase
H 0 * * * % Browser=Chrome;Environment=Test;TestCase=TestCase
H 0 * * * % Browser=Firefox;Environment=Test;TestCase=TestCase
H 0 * * * % Browser=Safari;Environment=Test;TestCase=TestCase
''')
}

rootPOM("pom.xml")
goals("clean test -DBrowser='$BROWSER' -DEnvironment='$ENVIRONMENT' -DTestCase='$TESTCASE'");

publishers {
archiveArtifacts {
pattern('target/surefire-reports/customized-emailable-report.html')
pattern('target/surefire-reports/emailable-report.html')
pattern('target/surefire-reports/index.html')
pattern('target/surefire-reports/screenshots/**')
}
wsCleanup {
includePattern('target/surefire-reports/**')
deleteDirectories(true)
}
}
}
}
}

PortalDSL.groovy

import JenkinsDSL;

def job = new JenkinsDSL(
gitUrl: 'giturl',
gitRemoteName: 'gitname',
gitBranch: 'gitbranch',
gitCredentials: 'gitcreds'
)

/********************************** Project 1 **********************************/

/***************** Test Suite 1 *****************/

/*** Test Case 1 ***/
job.addJob(
this,
'projectName',
'testSuite',
'testCase1',
'Some Description'
)
/*** Test Case 2 ***/
job.addJob(
this,
'projectName',
'testSuite',
'testCase2',
'Some Description'
)

Jenkins 错误信息

Processing DSL script JenkinsDSL.groovy
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'org.codehaus.groovy.runtime.InvokerHelper$1@620c0d02' with class 'org.codehaus.groovy.runtime.InvokerHelper$1' to class 'javaposse.jobdsl.dsl.JobParent'
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader$_runScripts_closure1.doCall(AbstractDslScriptLoader.groovy:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2040)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2025)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2078)
at org.codehaus.groovy.runtime.dgm$164.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts(AbstractDslScriptLoader.groovy:46)
at javaposse.jobdsl.plugin.ExecuteDslScripts.perform(ExecuteDslScripts.java:323)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1727)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
ERROR: Cannot cast object 'org.codehaus.groovy.runtime.InvokerHelper$1@620c0d02' with class 'org.codehaus.groovy.runtime.InvokerHelper$1' to class 'javaposse.jobdsl.dsl.JobParent'
Finished: FAILURE

最佳答案

看起来这可能是由于我在 Jenkins 中的配置所致。在“处理作业 DSL”->“查看文件系统”->“DSL 脚本”中,我输入了“*.groovy”。相反,我应该输入“PortalDSL.groovy”

ellak 指出我的代码中也有 Jenkins Pipeline,但我更新了代码以不包含 Pipeline 语法。

关于 Jenkins DSL 工作 : GroovyCastException Cannot cast object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53073190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com