2017-02-16 132 views
0

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

您可以通过定义包含你的脚本并返回结果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" 
} 
相关问题