【问题标题】:Can i call an another function from my function in Jenkins pipeline?我可以从 Jenkins 管道中的函数调用另一个函数吗?
【发布时间】:2019-08-13 06:24:24
【问题描述】:

我的 Jenkins 管道中有两个独立的函数,我想从第二个函数调用第一个函数。

我尝试了以下代码。

def first(){
    return{
        stages{
            stage("test"){
                steps{
                    echo "ok"
                }
            }
        }
     }
}

 def second(){
     return{
        first().call()
    }
}


pipeline {
    agent any
    stages{
       stage("Run"){
            steps{
                script{
                    second().call()

                }

            }

        }

   }

}

这是否可能。建议我正确的方式。

【问题讨论】:

    标签: function jenkins-pipeline nested-function


    【解决方案1】:

    是的,你可以。您的 Jenkinsfile 将如下所示:

    def first(){
        stage("test"){
            println "executing first"
        }  
    }
    
    def second(){
        println("calling first from second")
        first()
    }
    
    
    pipeline {
        agent any
        stages{
           stage("Run"){
                steps{
                    second()
                }
            }
        }
    }
    

    【讨论】:

    猜你喜欢
    • 2021-07-14
    • 1970-01-01
    • 2015-08-18
    • 2015-10-21
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 2023-03-16
    • 2012-01-16
    相关资源
    最近更新 更多