1

I am trying to create super class (common) and a subclass (specific), my plan is to have the common functions defined in super and override it in subclasses as needed, I am trying to write/run my very first super and subclass and it fails as shown below, any help with this please? sorry if this looks stupid, I have no experience with java/groovy, just started with groovy.

src/org/common.groovy:

$ cat src/org/common.groovy
package org

class common {
    def steps

    common(steps) {this.steps = steps}

    def sayHi() {
        steps.sh('''
                    echo "hi"
                ''')
    }
}

src/org/specific.groovy:

$ cat src/org/specific.groovy
package org

//import org.common

class specific extends common {
    def steps
    specific(steps) { this.steps = steps}

    def sayHi() {
        super.sayHi()
    }
}

vars/testSrc.groovy:

$ cat vars/testSrc.groovy
import org.specific
 def call() {
    def tst = new specific(this)
    tst.sayHi()
}

$

My pipeline script in Jenkins:

@Library('jenkins-library') _
pipeline {
    agent { label 'my-servers' }

    stages {
        stage('test') {
            steps {
                script {
                    testSrc()
                }
            }
        }
    }
}

Error:

java.lang.NoSuchMethodError: org.common: method <init>()V not found

Your Answer

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

Browse other questions tagged or ask your own question.