这类似于我提交的一个问题(
   
    JENKINS-49826
   
   ).这是詹金斯管道中的CPS编译问题。我会针对
   
    
     workflow-cps-plugin
    
   
   因为这绝对不是故意的行为。
  
  
   同时,我会把你的
   
    takeWhile
   
   打电话给
   
    @NonCPS
   
   注释方法,并将所有内容作为参数传入。看见
   
    this question and answer for some information on
    
     @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
  
   请注意,返回的类型来自不同的类型
   
    @非现金
   
   是
   
    java.util.ArrayList
   
   与…相比
   
    java.lang.Boolean
   
   .