首页 > 解决方案 > 在管道步骤之间传递值/数据

问题描述

你好!

我需要在 Jenkins 管道中将数据从一个步骤传递到另一个步骤。像这样的东西:

node { 
    // myPipelineStep is "my" own hello world pipeline step based on hello-world archetype, and I want it to return a variable that I have inside the plugin
    def return_value = myPipelineStep inputVariable: value

    // Then I want to do something else, a new step, where I use this value
    sh 'echo $return_value'

    //But the problem is I dont know how to return something from my pipeline step
}

但是在原型空插件中,应该执行操作的 perform() 函数是无效的。所以这里不可能返回一些东西。 在此处输入图像描述

hello-world achetype 也是如此。 在此处输入图像描述

有任何线索的人吗?

标签: jenkinsjenkins-pluginsjenkins-pipelinepipeline

解决方案


您可以修改方法中的内容吗?如果是这样,请在外部创建一个全局变量并在方法内部分配值。

现在变量将具有值,您可以在其他方法中使用它,例如

   node{
def isVaild
void perform(.....) {
    //do stuff
    isValid =true;
}

@Override
void perform(.....) {
    //do stuff
    if(isValid){
    }
}

}

它应该工作:)


推荐阅读