2017-02-16 15 views
0

私はJenkinsパイプラインプラグインを使用してプロジェクトをテストしています。私はmasterにマージする機能ブランチを持っている場合ノードでタスクを2回実行する

node { 

    stage("checkout") { 
    //some other code 
    } 

    stage("build") { 
    //some other code 
    } 

    stage("SonarQube Analysis") { 
    //some other code 
    } 

} 

、私が最初に機能上、masterにこのプロセスを行うと、かどうかを確認したいと思います:私は、次の形式のGroovyのスクリプトを持っています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" 
} 
関連する問題