我有一个共享库回购,其结构如下:
(root)
+- src
| +- com
| +- company
| +- DeploySteps.groovy
+- vars
| +- MainDeploySteps.groovy
该库通过Jenkinsfile导入到工作,如下所示:
library identifier: 'jenkinslib@master',retriever: modernSCM(
[$class : 'GitSCMSource',remote : 'git@url.to.git:jenkinslib.git',credentialsId: 'jenkins-credentials'])
src / com / company / DeploySteps.groovy中的回购中的类具有要包含在Jenkinsfile中的方法(例如CheckoutSCM)。
DeploySteps.groovy:
def CheckoutSCM() {
useful steps here
}
是否可以像这样在Jenkinsfile中包含此特定方法
import com.company.DeploySteps
然后像这样使用它:
CheckoutSCM('repo-here')
稍后在Jenkinsfile中?我读过documentation多次,但找不到答案,是否有可能从src
文件夹中导入某些内容,而不仅是从vars
中导入。
为什么要问,因为现在是在导入时:import com.company.DeployUtils
,然后尝试调用方法CheckoutSCM()
,看到Jenkins控制台输出中的错误:
java.lang.NoSuchMethodError:找不到这样的DSL方法“ CheckoutSCM” 在步骤之间
下面列出了可用方法,其中肯定没有CheckoutSCM
)
那么,从src
文件夹到Jenkinsfile的导入类是否可能?
P.S。我可以在
中访问Jenkinsfile MainDeployStepsMainDeploySteps {}
没有问题。