- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,我在 Jenkinsfile
中有一些代码,takeWhile
函数在 jenkins 中运行时返回一个 bool 值,但在实际的 groovy 中返回一个列表(正如预期的那样!)执行。整个脚本在本地运行结束,但在 jenkins 中失败,因为我将 takeWhile
的结果用作 List
,即使 jenkins 版本是 Boolean
我的同事推测插件安全管理器正在干扰。这是我唯一能想到的。
本地 groovy 版本:
$ groovy -version
Groovy Version: 2.4.14 JVM: 1.8.0_131 Vendor: Oracle Corporation OS: Mac OS X
Jenkins 版本:
Jenkins ver. 2.107.3
代码:
#!/usr/bin/env groovy
try {
def deployTo = [
'pre' : ['us-east-1'],
'int' : ['us-east-1'],
's1' : ['ca-central-1', 'us-east-1'],
'demo': ['us-east-1'],
].collectMany { k, v -> v.collect { r -> [k, r] } }
def failure = deployTo.findResult { entry ->
def result = 0
stage("Deploying to:\n${entry[0]}\n(${entry[1]})") {
println("stage deploy")
}
return new Random().nextBoolean() ? entry : null
}
println("deployto is a : ${deployTo.class}")
println("deploy to: ${deployTo}")
def takeWhile = deployTo.takeWhile { it != failure }
println("takeWhile is a : ${takeWhile.class}")
println("takeWhile to: ${takeWhile}")
takeWhile.each { toRollback ->
println("torollback is a ${toRollback.class}")
stage("Rolling back to:\n${toRollback[0]}\n(${toRollback[1]})") {
println("stage rollback")
}
}
} catch (e) {
println(e.getStackTrace().join('\n'))
println(e.class)
println(e.message)
throw e
}
本地常规输出:
Deploying to:
pre
(us-east-1)
stage deploy
Deploying to:
int
(us-east-1)
stage deploy
deployto is a : class java.util.ArrayList
deploy to: [[pre, us-east-1], [int, us-east-1], [s1, ca-central-1], [s1, us-east-1], [demo, us-east-1]]
takeWhile is a : class java.util.ArrayList
takeWhile to: [[pre, us-east-1]]
torollback is a class java.util.ArrayList
Rolling back to:
pre
(us-east-1)
stage rollback
Jenkins 输出:
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] stage
[Pipeline] { (Deploying to:
pre
(us-east-1))
[Pipeline] echo
stage deploy
[Pipeline] }
[Pipeline] // stage
[Pipeline] echo
deployto is a : class java.util.ArrayList
[Pipeline] echo
deploy to: [[pre, us-east-1], [int, us-east-1], [s1, ca-central-1], [s1, us-east-1], [demo, us-east-1]]
[Pipeline] echo
takeWhile is a : class java.lang.Boolean
[Pipeline] echo
takeWhile to: false
No such getAt method found: method java.lang.Boolean[java.lang.Integer]. Administrators can decide whether to approve or reject this signature.
[Pipeline] echo
torollback is a class java.lang.Boolean
[Pipeline] echo
org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetArray(SandboxInterceptor.java:451)
org.kohsuke.groovy.sandbox.impl.Checker$10.call(Checker.java:419)
org.kohsuke.groovy.sandbox.impl.Checker.checkedGetArray(Checker.java:424)
com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getArray(SandboxInvoker.java:45)
com.cloudbees.groovy.cps.impl.ArrayAccessBlock.rawGet(ArrayAccessBlock.java:21)
WorkflowScript.run(WorkflowScript:29)
com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2030)
com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:1890)
WorkflowScript.run(WorkflowScript:27)
___cps.transform___(Native Method)
com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
sun.reflect.GeneratedMethodAccessor703.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
com.cloudbees.groovy.cps.Next.step(Next.java:83)
com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
[Pipeline] echo
class org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException
[Pipeline] echo
No such getAt method found: method java.lang.Boolean[java.lang.Integer]
[Pipeline] End of Pipeline
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such getAt method found: method java.lang.Boolean[java.lang.Integer]
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetArray(SandboxInterceptor.java:451)
at org.kohsuke.groovy.sandbox.impl.Checker$10.call(Checker.java:419)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetArray(Checker.java:424)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getArray(SandboxInvoker.java:45)
at com.cloudbees.groovy.cps.impl.ArrayAccessBlock.rawGet(ArrayAccessBlock.java:21)
at WorkflowScript.run(WorkflowScript:29)
at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2030)
at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:1890)
at WorkflowScript.run(WorkflowScript:27)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
at sun.reflect.GeneratedMethodAccessor703.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:122)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
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 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)
Finished: FAILURE
最佳答案
这类似于我提交的问题 (JENKINS-49826)。这是 Jenkins Pipeline 中的 CPS 编译问题。我会针对 workflow-cps-plugin
提交错误因为这绝对不是预期的行为。
与此同时,我会将您的takeWhile
调用移动到一个@NonCPS
注释方法并将所有内容作为参数传递。参见 this question and answer for some information on @NonCPS
.
这是您的示例,简化为一个小型复制器,以及您可以将逻辑移动到 @NonCPS
的方法:
final deployTo = [
'pre' : ['us-east-1'],
'int' : ['us-east-1'],
's1' : ['ca-central-1', 'us-east-1'],
'demo': ['us-east-1'],
].collectMany { k, v -> v.collect { r -> [k, r] } }
final failure = [pre: 'us-east-1']
echo "${deployTo}"
echo "${deployTo.getClass()}"
def takeWhile = deployTo.takeWhile { it != failure }
println("takeWhile is a : ${takeWhile.class}")
println("takeWhile to: ${takeWhile}")
def nonCpsUsage = nonCpsTakeWhile(deployTo, failure)
println("nonCpsTakeWhile is a : ${nonCpsUsage.class}")
println("nonCpsTakeWhile to: ${nonCpsUsage}")
@NonCPS
def nonCpsTakeWhile(final d, final f) {
return d.takeWhile { it != f }
}
输出:
Started
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] echo
[[pre, us-east-1], [int, us-east-1], [s1, ca-central-1], [s1, us-east-1], [demo, us-east-1]]
[Pipeline] echo
class java.util.ArrayList
[Pipeline] echo
takeWhile is a : class java.lang.Boolean
[Pipeline] echo
takeWhile to: true
[Pipeline] echo
nonCpsTakeWhile is a : class java.util.ArrayList
[Pipeline] echo
nonCpsTakeWhile to: [[pre, us-east-1], [int, us-east-1], [s1, ca-central-1], [s1, us-east-1], [demo, us-east-1]]
[Pipeline] End of Pipeline
Finished: SUCCESS
请注意 @NonCPS
的返回类型是 java.util.ArrayList
与 java.lang.Boolean
的不同类型。
关于Jenkinsfile takeWhile 在 Jenkins 上返回 Boolean,但在实际的 groovy 中返回 ArrayList。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50634043/
在我针对 SQL Server 2012 实例运行的以下 Linq 查询中,我尝试读取最新记录,直到之前建立的 MasterId标记(这是一个 Guid )。 var cdc = crm.CdcCon
我正在运行以下代码: val it = List(1,1,1,2,2,3,3).iterator.buffered val compare = it.head it.takeWhile(_ ==
我有一些从 Haskell 调用的用 C 语言编写的函数。这些函数返回 IO (CInt) .有时我想运行所有函数,而不管它们返回什么,这很容易。为了示例代码,这是当前正在发生的事情的一般概念: Pr
我有一个 RxJS5 管道看起来像这样 Rx.Observable.from([2, 3, 4, 5, 6]) .takeWhile((v) => { v !== 4 }) 我想保留订阅直到看到
我是 Haskell 的新手,正在尝试执行以下操作: takeWhile (length < 3) [[1],[1,2],[1..3],[1..4]] .但这给出了一个错误,我认为这是因为 takeW
我有类似以下内容: [bla z|n 1) , let z = 10*n , _ ) = ap instance Monad F w
我想要一些能够有效地执行与 TakeWhile 相同但返回两个序列的东西: TakeWhile 的结果 1. 删除了输入序列的其余部分 我知道我可以做这样的事情: var a = input.Take
如何编写一个 takeWhile 来保留第一个不符合条件的元素? 示例(显然我的示例比这更棘手): 而不是 takeWhile (\× - > x! = 3) [1..10]返回 [1,2]我需要[1
我想要一些能够有效地执行与 TakeWhile 相同但返回两个序列的东西: TakeWhile 的结果 1. 删除了输入序列的其余部分 我知道我可以做这样的事情: var a = input.Take
似乎没有 e.TakeWhile(predicate, atLeastNElements) 重载。有没有一种方便的方式来表达TakeWhile,但是,如果有>= N个元素可用的话,至少要取N个元素。?
如何使用折叠在 Haskell 中实现 takeWhile 函数? takeWhile :: (a -> Bool) -> [a] -> [a] 我尝试了一种类似于实现这样的过滤器的策略 filter
我想知道是否有办法添加根据方法 takeWhile() 的条件测试的流的最后一个元素。我相信我想实现类似于 RxJava 的 takeUntil() 方法的东西。 我猜没有直接的方法可以做到这一点(如
有 public static IEnumerable FibonacciNumbers() { long current = 0; long next = 1; while (true) {
我想在 LINQ to Objects 上使用 LINQ TakeWhile 函数。但是,我还需要知道“破坏”函数的第一个元素,即条件不成立的第一个元素。 是否有一个函数可以获取所有不匹配的对象以及第
takeWhile() 与 Java 9 中的 filter() 有何不同。它有什么额外的实用程序? Stream.of(1,2,3,4,5,6,7,8,9,10).filter(i -> i i
我正在使用 takeWhile 创建片段来探索它的可能性。与 flatMap 配合使用时,行为不符合预期。请在下面找到代码片段。 String[][] strArray = {{"Sample1",
val i = (1 to 8).toIterator val oneToThree = i.takeWhile(_ val i = (1 to 8).iterator i: Iterator[In
我看到它们(where 和 takeWhile)具有相同的功能..否则我可能会在这里漏掉一些东西! 最佳答案 documentation for Iterable.where说: Returns a
isqrt :: Integer -> Integer isqrt = floor . sqrt . fromIntegral primes :: [Integer] primes = sieve [
Javadoc指出 This is a short-circuiting stateful intermediate operation. 有状态的定义来自 Javadoc : Stateful op
我是一名优秀的程序员,十分优秀!