在节点中运行两次任务

时间:2017-02-16 14:52:44

标签: jenkins groovy

我正在使用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"
}

这样的事情可能吗?

1 个答案:

答案 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"
}