为什么从DSL而不是通过jenkins文件访问jenkins currentBuild时会有所不同?
所以这是一个棘手的问题,我不希望有太多的答案,但我被阻止,因为这一点 有以下管道:为什么从DSL而不是通过jenkins文件访问jenkins currentBuild时会有所不同?,jenkins,jenkins-plugins,jenkins-groovy,jenkins-job-dsl,Jenkins,Jenkins Plugins,Jenkins Groovy,Jenkins Job Dsl,所以这是一个棘手的问题,我不希望有太多的答案,但我被阻止,因为这一点 有以下管道: timestamps{ node() { ws("workspace/Maintenance/Sandbox") { stage("Via jenkins file") { def causes = currentBuild.rawBuild.getCauses().
timestamps{
node() {
ws("workspace/Maintenance/Sandbox") {
stage("Via jenkins file") {
def causes = currentBuild.rawBuild.getCauses().properties
echo "From jenkinsfile currentBuild is " + currentBuild.class + " " + currentBuild.toString()
echo "From jenkinsfile rawBuild is " + currentBuild.rawBuild.class + " " + currentBuild.rawBuild.toString()
causes.each { cause ->
echo cause.class.name
}
}
stage("Via DSL") {
printCauses()
}
}
}
}
并将printCauses()
定义为共享库中的DSL(将printCauses.groovy
文件放在vars
文件夹中),如下所示:
def call() {
def causes = currentBuild.rawBuild.getCauses().properties
echo "From DSL currentBuild is " + currentBuild.class + " " + currentBuild.toString()
echo "From DSL rawBuild is " + currentBuild.rawBuild.class + " " + currentBuild.rawBuild.toString()
causes.each { cause ->
echo "Cause class is " + cause.class.name
}
}
相同的代码,对吗
这是我在第一阶段得到的结果:
17:45:02来自文件currentBuild的类为org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper@43d6afd1
[管道]回声
17:45:02来自文件rawBuild的类是org.jenkinsci.plugins.workflow.job.WorkflowRun维护/Sandbox#55
[管道]回声
17:45:02hudson.triggers.TimerTrigger$TimerTriggerCause
第二阶段:
17:45:02来自DSL currentBuild的类是org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper@2c12d495
[管道]回声
17:45:02来自DSL的rawBuild是org.jenkinsci.plugins.workflow.job.WorkflowRun维护/Sandbox#55类
[管道]回声
17:45:02原因类是java.util.AbstractMap$SimpleMultiTableEntry
显然,RunWrapper是不同的。
问题是我需要从DSL中识别TimerTriggerCause,它被我没有得到正确的RunWrapper实例这一事实所掩盖
我能做些什么来解决这个问题?即使将currentBuild作为jenkins的参数传递给DSL也不起作用。我希望通过一个引用,但其原因最终还是被掩盖了。