Ame*_*sse 4 groovy artifactory jenkins jenkins-pipeline
我有这个Jenkinsfile
:
stage('Artifactory Deploy') {
options {
timeout(time: 5, unit: 'MINUTES')
}
when {
anyOf {
branch "master"
branch "develop"
}
}
steps {
withMaven(jdk: "${JDK_VERSION}", maven: 'M3') {
script {
def server = Artifactory.server('itext-artifactory')
def rtMaven = Artifactory.newMavenBuild()
rtMaven.deployer server: server, releaseRepo: 'releases', snapshotRepo: 'snapshot'
rtMaven.tool = 'M3'
def buildInfo = rtMaven.run pom: 'pom.xml',
goals: "--threads 2C --no-transfer-progress " +
"install --activate-profiles artifactory " +
"-Dmaven.repo.local=${env.WORKSPACE.replace('\\','/')}/.repository"
server.publishBuildInfo buildInfo
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
${env.WORKSPACE.replace('\\','/')}
是必需的,因为虽然 Linux 的行为符合预期,但 Windows 显然表现得像 T?????o?????????????n???y?????????? ??????这????????????????????小马??????关于路径分隔符。
我宁愿有
withMaven(jdk: "${JDK_VERSION}", maven: 'M3', mavenLocalRepo: '.repository')
Run Code Online (Sandbox Code Playgroud)
但我们不能有好东西。
无论如何,在 Jenkins 上运行它时,我收到以下错误:
java.lang.ClassCastException: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String
at org.jfrog.hudson.pipeline.common.types.builds.MavenBuild.run(MavenBuild.java:56)
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 groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:160)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:158)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:162)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at WorkflowScript.run(WorkflowScript:193)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at sun.reflect.GeneratedMethodAccessor290.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.dispatch(CollectionLiteralBlock.java:55)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.item(CollectionLiteralBlock.java:45)
at sun.reflect.GeneratedMethodAccessor340.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:107)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at sun.reflect.GeneratedMethodAccessor290.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:89)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at sun.reflect.GeneratedMethodAccessor290.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Run Code Online (Sandbox Code Playgroud)
并且没有工件被部署到 Artifactory(并且构建失败)。
如何解决这个问题?上游错误修复或本地解决方法。
在 Stack Overflow 上发布我的问题是因为我们拥有 Artifactory Pro 许可证,而 Jfrog 的客户支持门户仅适用于 Pro X、Enterprise 和 Enterprise+ 客户。其他客户被定向到 Stack Overflow,请参阅https://jfrog.com/support/。
一个可能的根本原因是在GStringImpl的评论中发现的东西不能转换为 java.lang.String:
如果您尝试将 a 分配给
GString
静态类型为 as 的内容String
(或GString
为String
-type 方法参数传递 a ),则 Groovy 将为您进行转换,但如果您分配给类型为 as 的内容,Object
则必须自己进行转换.
因为我在花括号 ( ${env.WORKSPACE.replace('\\','/')}
) 中使用了一个变量,所以我会自动使用 GroovyGString
而不是 Java String
。
所以,Jfrog 员工,如果您正在artifactory
Stack Overflow 上监控标签:根据Artifactory 插件的Jenkins 文档,goals
被定义为 type String
,但显然情况并非如此,因为 Groovy 无法进行转换?你能确认或解释吗?谢谢!
编辑
我找到了Jenkins Artifactory Plugin API Javadocs和将 a作为参数的run()
方法org.jfrog.hudson.pipeline.common.types.builds.MavenBuild
Map
:
public void run(Map<String,Object> args)
Run Code Online (Sandbox Code Playgroud)
因此,确实,虽然 Groovy 会自动执行从 GroovyGString
到 JavaString
的转换,但它不会执行从 GroovyGstring
到Object
内部Map
.
解决方法
如链接问题中所述,我添加.toString()
手动将 Groovy 转换GString
为 Java String
。
所以
def buildInfo = rtMaven.run pom: 'pom.xml',
goals: "--threads 2C --no-transfer-progress " +
"install --activate-profiles artifactory " +
"-Dmaven.repo.local=${env.WORKSPACE.replace('\\','/')}/.repository"
Run Code Online (Sandbox Code Playgroud)
变成了
def buildInfo = rtMaven.run pom: 'pom.xml',
goals: "--threads 2C --no-transfer-progress " +
"install --activate-profiles artifactory " +
"-Dmaven.repo.local=${env.WORKSPACE.replace('\\','/')}/.repository".toString()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1700 次 |
最近记录: |