Thami Bouchnafa
Thami Bouchnafa

Reputation: 2167

How can I define a custom pipeline directive?

For example something like:

pipeline {
   customDirective {
      sh "env"
      ..
   }
}

Upvotes: 1

Views: 678

Answers (2)

Banoona
Banoona

Reputation: 1650

This works:

customDirective.groovy (Shared Library)

def call(Closure body) {
     def config = [:]
     body.resolveStrategy = Closure.DELEGATE_FIRST
     body.delegate = config
     body()
     config.script()
}

Jenkinsfile

customDirective {
     url="http://something.another.com"
     title="The Title"
     script = {
          sh "env"
     }
 }

Upvotes: 0

Philip
Philip

Reputation: 3078

This is currently not possible. You can only define custom pipeline steps via a Shared Library and use them within the stage/steps section and in the condition block of the post section. If you need for any reasons more customization you would have to have a look into the Scripted pipeline syntax. It allows to use most functionality of Groovy and is therefore very flexible.

Upvotes: 2

Related Questions