在为Actor编写Specs2规范时,我MatchError对一些部分函数的组合感到有点困惑.
一个最小的例子:
val testPf1 = PartialFunction[Any, Boolean]{ case 2 ? true }
val testPf2 = PartialFunction[Any, Boolean]{ case 1 ? true }
val testPf = testPf1 orElse testPf2
testPf.isDefinedAt(1)
testPf.isDefinedAt(2)
testPf(1)
testPf(2)
Run Code Online (Sandbox Code Playgroud)
导致输出:
testPf1: PartialFunction[Any,Boolean] = <function1>
testPf2: PartialFunction[Any,Boolean] = <function1>
testPf: PartialFunction[Any,Boolean] = <function1>
res0: Boolean = true
res1: Boolean = true
scala.MatchError: 1 (of class java.lang.Integer)
at com.dasgip.controller.common.informationmodel.programming.parametersequence.A$A161$A$A161$$anonfun$testPf1$1.apply(PFTest.sc0.tmp:33)
at com.dasgip.controller.common.informationmodel.programming.parametersequence.A$A161$A$A161$$anonfun$testPf1$1.apply(PFTest.sc0.tmp:33)
at scala.PartialFunction$$anonfun$apply$1.applyOrElse(PFTest.sc0.tmp:243)
at scala.PartialFunction$OrElse.apply(PFTest.sc0.tmp:163)
at #worksheet#.#worksheet#(PFTest.sc0.tmp:36)
Run Code Online (Sandbox Code Playgroud)
那让我很困惑.如果对于给定输入isDefinedAt的两个部分函数的组合返回true,我希望我也可以将apply它输出到同一个.
我正在尝试检索存储在 Jenkins 文件脚本块中的 Jenkins 凭证中的值,但无法检索该值
我的詹金斯文件中的以下块有效
我有一个 Jenkins 文件,它使用存储在 jenkins 凭据中的凭据值设置环境变量:
environment {
CERT_CLIENT_TH = credentials("stored.cred.name")
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在脚本块中执行相同的操作时,我无法检索凭据。
script {
env.CERT_CLIENT_TH = credentials("stored.cred.name")
}
Run Code Online (Sandbox Code Playgroud)
当我使用 echo 检查使用这两种方法的输出时"${env.CERT_CLIENT_TH}"
当进入环境块时,输出如预期的那样是“****”,因为它是加密的凭证值。
当我尝试在脚本块中获取凭据时,回显输出是
@credentials(<anonymous>=stored.cred.name)
Run Code Online (Sandbox Code Playgroud)
如何在 Jenkins 文件的脚本块中获取凭据?
groovy credentials environment-variables jenkins jenkins-pipeline