jenkins的pipeline 的序列化的概念【java.io.NotSerializableException】
- pipeline里面的数据只能是字符串或者数字,其他不能被序列化的参数会报错
https://stackoverflow.com/questions/37864542/jenkins-pipeline-notserializableexception-groovy-json-internal-lazymap
- 出现错误java.io.NotSerializableException【project不是字符串或者数字】
def getProject(projectName) {
def project = hudson.model.Hudson.instance.getItemByFullName(projectName)
if (!project) {error("Project not found: $projectName")}
return project
}
stage('Demo') {
project = getProject('add_build_info') //这一步会出错
def getUrl = project.lastBuild.getUrl()
println(getUrl)
}
- OK【没有返回project,而是字符串】
def getProject(projectName) {
def project = hudson.model.Hudson.instance.getItemByFullName(projectName)
if (!project) {error("Project not found: $projectName")}
return project.lastBuild.getUrl()
}
stage('Demo') {
project = getProject('add_build_info')
println(project)
}
https://www.jenkins.io/doc/book/pipeline/shared-libraries/
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}"
}
}