我正在尝试为 Jenkins 管道项目构建一个可重用的库,但我似乎无法弄清楚如何获取构建状态以及设置它。如果我使用 Jenkinsfile 或 vars 脚本,它可以工作,但我感兴趣的是使用 src/ 库结构。
我已经设法通过使用接口使其他东西正常工作,例如常规的 git、sh、节点、阶段步骤,但我无法让“currentBuild”包装器工作。我尝试了很多东西,我想我需要使用 RunWrapper,但我无法弄清楚。
以前我可以直接在我的流水线脚本中使用以下块,现在我想把它移到我的库中: currentBuild.result = "UNSTABLE"
在使用 src 时,我相信您使用 new 关键字调用该文件。您是否尝试过从 JenkinsFile 传递脚本元素
示例 JenkinsFile
@Library('somalib@version')
import com.mypackage.MyClass //this is inside src folder
new MyClass(this).execute() //pass this to constructor
你的 MyClass 看起来像
package com.mypackage
class MyClass {
this.script
MyClass(script){
this.script = script
}
execute(){
script.node('nodeName'){
script.echo(script.currentBuild.result)
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句