0

I want to customize the powerShell() method in jobDSL

a .groovy file with some job dsl defined jobs

def betterPowerShell(def cmd) {
    powerShell("$cmd; exit \$LastExitCode")
}

Since I am out of the

job {
  step {
  }
}

context this is not working...

Maybe I need something like...

def betterPowerShell(def cmd) {
    javaposse.jobdsl.dsl.helpers.step.StepContext.powerShell("$cmd; exit \$LastExitCode")
}
David West
  • 1,533
  • 3
  • 18
  • 25

1 Answers1

1

What you want is a Jenkins shared library which will allow you to (among other things) define custom Pipeline DSL steps in a repository you own. See the "Defining custom steps" section in that document.

Here's the example custom step from that document:

// vars/sayHello.groovy
def call(String name = 'human') {
    // Any valid steps can be called from this code, just like in other
    // Scripted Pipeline
    echo "Hello, ${name}."
}
jayhendren
  • 3,022
  • 8
  • 16