美文网首页
pipeline class 使用

pipeline class 使用

作者: AppleLin_cdea | 来源:发表于2021-10-12 21:10 被阅读0次

    2021年10月12日20:58:29 星期二
    pipeline 如何使用 class 例子

    示例代码

    import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
    
    class CDemo  implements Serializable
    {
        def script
        def m_is_cov
        def CDemo(sci)
        {
            this.script = sci
        }
        
        def set(is_cov=false)
        {
            m_is_cov = is_cov
            script.echo "m_is_cov is "+m_is_cov
        }
    }
    
    node('general')
    {
        stage('cov') {
            obj = new CDemo(this)
            obj.set(true)
            obj.set(false)
        }
    }
    

    运行结果

    Console Output
    21:04:00 Started by user Apple
    21:04:00 Running in Durability level: MAX_SURVIVABILITY
    21:04:00 [Pipeline] Start of Pipeline
    21:04:00 [Pipeline] node
    21:04:00 Running on general in /home/jenkins/workspace/demo
    21:04:00 [Pipeline] {
    21:04:00 [Pipeline] stage
    21:04:00 [Pipeline] { (cov)
    21:04:00 [Pipeline] echo
    21:04:00 m_is_cov is true
    21:04:01 [Pipeline] echo
    21:04:01 m_is_cov is false
    21:04:01 [Pipeline] }
    21:04:01 [Pipeline] // stage
    21:04:01 [Pipeline] }
    21:04:01 [Pipeline] // node
    21:04:01 [Pipeline] End of Pipeline
    21:04:02 Finished: SUCCESS
    

    总结类

    • 定义类的时候加 implements Serializable
    • 类 class 要有构建函数,传 script
    • 调用函数 set(参数), 不能 set(is_cov=true),应该是 set(true) 或者 set(false)

    相关文章

      网友评论

          本文标题:pipeline class 使用

          本文链接:https://www.haomeiwen.com/subject/jtyjoltx.html