Answers: <p>What you want is a <a href="https://www.jenkins.io/doc/book/pipeline/shared-libraries/" rel="nofollow noreferrer">Jenkins shared library</a> which will allow you to (among other things) define custom Pipeline DSL steps in a repository you own.  See the <a href="https://www.jenkins.io/doc/book/pipeline/shared-libraries/#defining-custom-steps" rel="nofollow noreferrer">"Defining custom steps" section</a> in that document.</p>
  
  <p>Here's the example custom step from that document:</p>
  
  <pre><code>// 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}."
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-15T16:03:07.390Z
Answers: I wanted to call powerShell() from the powershell jobDSL plugin. Will that work in this context?
Answers: David West
Answers: CC BY-SA 4.0
Answers: 2020-05-15T20:41:46.543Z
Answers: 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.
Answers: jayhendren
Answers: CC BY-SA 4.0
Answers: 2020-06-16T18:17:06.047Z
Answers: how do you load the shared library in a Job DSL seed then? https://devops.stackexchange.com/questions/11833/how-do-i-load-a-jenkins-shared-library-in-a-jenkins-job-dsl-seed
Answers: David West
Answers: CC BY-SA 4.0
Answers: 2020-05-14T16:06:19.860Z
Answers: 2020-05-14T16:06:19.860Z
Answers: jayhendren
Body: <p>I want to customize the powerShell() method in jobDSL</p>
  
  <p>a .groovy file with some job dsl defined jobs</p>
  
  <pre><code>def betterPowerShell(def cmd) {
      powerShell("$cmd; exit \$LastExitCode")
  }
  </code></pre>
  
  <p>Since I am out of the </p>
  
  <pre><code>job {
    step {
    }
  }
  </code></pre>
  
  <p>context this is not working...</p>
  
  <p>Maybe I need something like...</p>
  
  <pre><code>def betterPowerShell(def cmd) {
      javaposse.jobdsl.dsl.helpers.step.StepContext.powerShell("$cmd; exit \$LastExitCode")
  }
  </code></pre>
  
Tags: <jenkins>
Title: How to customize a Jenkins job dsl method
UserDisplayName: David West
ThreadText: # How to customize a Jenkins job dsl method
  
  (Asked by: username_0 on 2020-05-13)
  
  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")
  }
  
  ```
  
  **Tags:** jenkins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-05-14. Score: 1
  
  What you want is a [Jenkins shared library](https://www.jenkins.io/doc/book/pipeline/shared-libraries/) which will allow you to (among other things) define custom Pipeline DSL steps in a repository you own. See the ["Defining custom steps" section](https://www.jenkins.io/doc/book/pipeline/shared-libraries/#defining-custom-steps) 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}."
  }
  
  ```
  
  > **Comments:**
  > **username_0**: I wanted to call powerShell() from the powershell jobDSL plugin. Will that work in this context?  
  > **username_1**: 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.  
  > **username_0**: how do you load the shared library in a Job DSL seed then? https://devops.stackexchange.com/questions/11833/how-do-i-load-a-jenkins-shared-library-in-a-jenkins-job-dsl-seed  
  
  ---
  
  