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")
}
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}."
}
| improve this answer | |
  • I wanted to call powerShell() from the powershell jobDSL plugin. Will that work in this context? – David West May 15 at 16:03
  • Yes, you can call other Pipeline steps from your custom Pipeline step. In fact most of the custom steps that I have written using this method call other Pipeline steps. – jayhendren May 15 at 20:41
  • how do you load the shared library in a Job DSL seed then? devops.stackexchange.com/questions/11833/… – David West Jun 16 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.