- jenkins共享库做模块封装时遇到的问题总结:
背景描述:使用jenkins共享库对SCM subversion操作进行封装时,使用了Checkout插件,生成的检出脚本代码为
checkout([$class: 'SubversionSCM',
additionalCredentials: [],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: '',
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [[
credentialsId: CRED_ID,
depthOption: 'infinity',
ignoreExternalsOption: true,
local: checkout_local_path,
remote: repo_url
]],
workspaceUpdater: [$class: 'UpdateUpdater']
]
)
把它封装到jenkins共享库的vars目录下边的scm_svn_checkout.groovy文件里,传参形式及代码demo为:
注意):(文件名scm_svn_checkout.groovy名字不能和调用的checkout()方法同名)不然构建时jenkins会报ERROR:hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: checkout.call() is applicable for argument types.)
def call(String CRED_ID,String checkout_local_path,String repo_url) {
checkout([$class: 'SubversionSCM',
additionalCredentials: [],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: '',
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [[
credentialsId: CRED_ID,
depthOption: 'infinity',
ignoreExternalsOption: true,
local: checkout_local_path,
remote: repo_url
]],
workspaceUpdater: [$class: 'UpdateUpdater']
]
)
}
jenkinsfile写法:
@Library('my-shared-library') _
pipeline {
agent {label "test"}
stages {
stage('Checkout') {
steps {
scm_svn_checkout.call("aaaaa","bbbbb","ccccc")
}
}
}
}
project repository base:
http:aa/bb/usvn/test_1
default version:branches/test/share_library,下边是src和vars
jenkins关于共享库配置时,
- 如果Default version写到了共享库这一层就可以加载到共享库的代码。共享库这一层是指vars,src所在的目录。
- 如果Default version写到了共享库层级的上(前)某一层,就需要在Library Path(Optional)这里以相对路径形式test/share_library拼接default version:branches.也可以获取到共享库代码。
![在这里插入图片描述](https://img-blog.csdnimg.cn/5a305adc80694d4381cbcbc5088abc68.png#pic_center