zoukankan      html  css  js  c++  java
  • Jenkinsfile 你如何加载一个groovy文件并执行它

    I have a jenkinsfile dropped into the root of my project and would like to pull in a groovy file for my pipeline and execute it. The only way that I've been able to get this to work is to create a separate project and use the fileLoader.fromGit command. I would like to do

    def pipeline = load 'groovy-file-name.groovy'
    pipeline.pipeline()
    
    解决方案

    If your JenkinsFile and groovy file in one repository and JenkinsFile is loaded from SCM you have to do:

    Example.Groovy

    def exampleMethod() {
        //do something
    }
    
    def otherExampleMethod() {
        //do something else
    }
    return this
    

    JenkinsFile

    node {
        def rootDir = pwd()
        def example = load "${rootDir}@script/Example.Groovy "
        example.exampleMethod()
        example.otherExampleMethod()
    }
    
     

    我有一个jenkinsfile放到我的项目的根目录下,并且希望为我的管道提供一个groovy文件并执行它。我能够得到这个工作的唯一方法是创建一个单独的项目并使用fileLoader.fromGit命令。我想要做的是

    def pipeline = load'groovy-file-name.groovy'
    pipeline.pipeline()

    解决方案

    如果您的JenkinsFile和groovy文件在一个存储库中,并且JenkinsFile从SCM加载,您必须这样做:

    Example.Groovy


    $ b

      def exampleMethod(){
    //做某事
    }

    def otherExampleMethod(){
    //做别的事
    }
    返回这个

    $ b

    JenkinsFile $ b

     节点{
    def rootDir = pwd()
    def example = load"${rootDir}@script/Example.Groovy"
    example.exampleMethod()
    example.otherExampleMethod()
    }
    我们只需要努力,然后剩下的交给时间。
  • 相关阅读:
    回调函数(callback)是什么?
    类和对象的关系
    前端性能优化十四个规则:
    响应时间过长而导致网页问题的原因?
    给老爸更换电脑
    Notes for "Python in a Nutshell"
    Debian Jessie升级至Stretch小记
    将LibreOffice文档转换为豆瓣日记
    将Emacs Org任务树导出至Freeplane思维导图
    GNU/Linux下Freeplane的界面渲染问题
  • 原文地址:https://www.cnblogs.com/lgj8/p/14863536.html
Copyright © 2011-2022 走看看