Я использовал функции, размещенные в / vars / разделяемых библиотек, и они работали нормально. Но мне нужно использовать классы сейчас. Чтобы изучить его, я создал 2 простых класса (родитель и его потомок), чтобы получить некоторую git информацию.
/ src / ptx / shared / GitInfo. groovy
package ptx.shared
class GitInfo implements Serializable{
public String commandMsg
public String commandId
public String commandAuthor
public String msg
public String id
public String author
def steps
public GitInfo(steps){
this.steps = steps
this.commandMsg = "git log --format=%B -n 1"
this.commandId = "git log -n 1 --pretty=format:'%h'"
this.commandAuthor = "git log -n 1 --format=%ae"
this.msg = this.runCommand(this.commandMsg)
this.id = this.runCommand(this.commandId)
this.author = this.runCommand(this.commandAuthor)
}
@NonCPS
public runCommand(command){
}
}
src / ptx / shared / LinuxGitInfo. groovy
package ptx.shared
//import ptx.shared.GitInfo
class LinuxGitInfo extends GitInfo {
public LinuxGitInfo(steps){
super(steps)
}
@NonCPS
public runCommand(command){
echo "something"
//return this.steps.sh(script: command, returnStdout: true).trim()
}
}
и мой конвейер
@Library('firstlibrary') _
import ptx.shared.*
pipeline{
agent { label 'agents'}
//libraries{
// lib('firstlibrary')
//}
environment{
GIT_CREDS = credentials('gitlab')
}
stages{
stage('git'){
steps{
git 'http://' + env.GIT_CREDS + '@10.11.22.112/root/pytest.git'
}
}
stage('lib functions'){
steps{
script{
//first.mySh('pwd')
def gitinfo = new LinuxGitInfo(this)
}
}
}
}
}
Но я получаю это
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: ptx.shared.LinuxGitInfo.echo() is applicable for argument types: (java.lang.String) values: [something]
Possible solutions: each(groovy.lang.Closure), getAt(java.lang.String), wait(), grep(), dump(), any()
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:81)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
...
С sh () тоже самое. Что мне не хватает?