如何复制DIR在Groovy中

发布于 2025-02-04 04:04:51 字数 356 浏览 6 评论 0原文

以下是我的管道代码:

dir(my_directory) {
      retry(1) {
             // something
      }
}

是否有可能通过管道上下文访问Groovy中的 dir

我在考虑下面这样的事情

class StepExecutor {
  // some code
    void dir(String directory, Closure statement) {
        this.steps.dir(directory) { statement }
    }
}

Below is my pipeline code :

dir(my_directory) {
      retry(1) {
             // something
      }
}

Is there a possibility to access dir step in groovy through the pipeline context ?

I'm thinking of something like this below

class StepExecutor {
  // some code
    void dir(String directory, Closure statement) {
        this.steps.dir(directory) { statement }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

意犹 2025-02-11 04:04:51

是的,你可以。不过,它要求您通过管道的步骤对象。

class StepExecutor {
  
  def steps;
  public StepExecutor(def steps) {
     this.steps = steps
  }
  // some code
    void dir(String directory, Closure statement) {
        this.steps.dir(directory) { statement }
    }
}

从管道内部创建对象:

pipeline { ....
   def stepExecutor = new StepExecutor(this);
...}

Yes you can. It requires you to pass the steps-object of the pipeline though.

class StepExecutor {
  
  def steps;
  public StepExecutor(def steps) {
     this.steps = steps
  }
  // some code
    void dir(String directory, Closure statement) {
        this.steps.dir(directory) { statement }
    }
}

creating the object from inside of your pipeline:

pipeline { ....
   def stepExecutor = new StepExecutor(this);
...}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文