简体   繁体   English

Groovy将装箱的类型传递给Jenkins,如何取消装箱?

[英]Groovy passes boxed types to Jenkins, how to unbox?

I'm trying to write a Jenkins pipeline that would restart Jenkins once a week if no jobs are running. 我正在尝试编写一个Jenkins管道,如果没有作业在运行,它将每周一次重新启动Jenkins。 Since I don't want to block running jobs for too long, I'm trying to call doQuietDown with the timeout argument. 由于我不想长时间阻塞正在运行的作业,因此我尝试使用timeout参数调用doQuietDown

https://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html#doQuietDown-boolean-int- https://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html#doQuietDown-boolean-int-

So that's what I'm trying: 这就是我正在尝试的方法:

        stage('Quiet Down') {
            steps {
                script {
                    boolean doBlock = true
                    int timeout_ms = 30000
                    Jenkins.doQuietDown(doBlock, timeout_ms)
                }
            }
        }

That fails: 失败了:

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: static jenkins.model.Jenkins.doQuietDown() is applicable for argument types: (java.lang.Boolean, java.lang.Integer) values: [true, 30000]
Possible solutions: doQuietDown(boolean, int), doQuietDown()
    at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1501)
    at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1487)

So groovy is passing boxed types, but Jenkins expects unboxed types. 因此,时髦正在传递盒装类型,但詹金斯希望使用非盒装类型。 I tried casts to unboxed types, booleanValue() and intValue() , using true and 30000 without variables, but all that made no difference to the error message. 我尝试使用true30000不带变量booleanValue()对未装箱的类型booleanValue()intValue()进行强制类型转换,但这对错误消息没有任何影响。

I also tried Jenkins.doQuietDown block: doBlock, timeout: timeout_ms but it's passing LinkedHashMap : 我还尝试了Jenkins.doQuietDown block: doBlock, timeout: timeout_ms但是它正在传递LinkedHashMap

jenkins.model.Jenkins.doQuietDown() is applicable for argument types: (java.util.LinkedHashMap) values: [[block:true, timeout:30000]]

I'm using Jenkins 2.180 (the current version at the time of this posting) 我正在使用Jenkins 2.180(本文发布时的当前版本)

It's not a static method. 这不是静态方法。 And you call it as a static. 您称其为静态。

You have to do something like Jenkins.get().doQuietDown(...) . 您必须执行Jenkins.get().doQuietDown(...)

Boxing/unboxing - groovy do it automatically. 装箱/拆箱-Groovy自动执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM