Home > Back-end >  How to replicate dir step in groovy
How to replicate dir step in groovy

Time:06-09

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 }
    }
}

CodePudding user response:

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);
...}
  • Related