Jenkinsfile usage characteristics and other groovy syntaxes

I would like to use a slightly more complex pipelining through jenkinsfiles with some repetitive steps, since I have many or similar projects. I am using jenkins 2.0 with pipeline plugins. I know that you can load groovy scripts, which may contain some common parts of the code, but I was wondering if these scripts can use some object-oriented groovy functions as traits. For example, I have a trait called Step:

package com.foo.something.ci 
trait Step {                                         
    void execute(){ echo 'Null execution'}                                 
}

And the class that then implemented the attribute in another file:

class Lint implements Step {
    def execute() {
        stage('lint')
        node {
            echo 'Do Stuff'
        }
    }
}

And another class containing the "main" function:

class foo {
   def f = new Lint()
   f.execute()
}

Jenkins, , , ? ?

+4
1

. groovy Jenkins.

Jenkinsfile , . , Jenkins, stage , Jenkins Pipeline.

: ,

package org.foo
class Utilities implements Serializable {
  def steps
  Utilities(steps) {this.steps = steps}
  def mvn(args) {
    steps.sh "${steps.tool 'Maven'}/bin/mvn -o ${args}"
  }
}

:

@Library('utils') import org.foo.Utilities
def utils = new Utilities(steps)
node {
  utils.mvn 'clean package'
}
+1

All Articles