我正在使用Jenkins管道插件来测试我的项目。我有一个以下形式的Groovy脚本:
node {
stage("checkout") {
//some other code
}
stage("build") {
//some other code
}
stage("SonarQube Analysis") {
//some other code
}
}
当我想要合并到master
的功能分支时,我想首先在master
上执行此过程,然后在功能上查看SonarQube分析在功能上是否更差
我想要这样的东西:
def codeCoverageMaster = node("master")
def codeCoverageFeature = node("feature/someFeature")
if(codeCoverageFeature < codeCoverageMaster) {
currentBuild.result = "ERROR"
}
这样的事情可能吗?
答案 0 :(得分:1)
您可以通过定义包含脚本的函数并返回SonarQube结果来实现,然后调用该函数两次并比较结果:
def runBranch(String path) {
def sonarQubeRes
node {
stage("checkout") {
//some other code
// Use path supplied to this function
}
stage("build") {
//some other code
}
stage("SonarQube Analysis") {
//some other code
}
}
return sonarQubeRes
}
def codeCoverageMaster = runBranch("master")
def codeCoverageFeature = runBranch("feature/someFeature")
if(codeCoverageFeature < codeCoverageMaster) {
currentBuild.result = "ERROR"
}