是否可以捕获maven build命令的输出-如果构建通过或失败?

时间:2019-05-01 11:22:23

标签: powershell maven

我正在使用Power Shell脚本克隆存储库并清理和构建它们。我想知道如何知道构建成功还是失败。我正在使用以下命令-

mvn clean install -DskipTests=true

只是想知道是否有某种方式可以捕获其输出以了解构建是通过还是失败。实际上,该脚本将在Jenkins中使用,因此想知道如何知道构建是否成功。

以下是我的Power Shell脚本,以防它有助于稍微了解我的问题或帮助有需要的人-

#Cloning/Pulling Repos
$localPath = "C:\Users\A12345\Documents\workspace-vs-code\Powershell\ClonedRepos\"
Get-Content .\CloneAllRepos.config | ForEach-Object {
    $repoLocation = $localPath + $_.Split('/')[-1]
    Write-Host($repoLocation)
    if(!(Test-Path -Path $repoLocation)) {
        Write-Host('Repo not found. Cloning repo for ' + $_.Split('/')[-1])
        git clone -b develop $_ $repoLocation
        Write-Host('Cloned Repo ' + $_.Split('/')[-1])
    } else {
        Write-Host('Repo found. Pulling repo' + $_.Split('/')[-1])
        git pull
        Write-Host('Pulled Repo ' + $_.Split('/')[-1])
    }
    $repoLocation = ''
}

#Clean And Build - Maven
$localPath = "C:\Users\A12345\Documents\workspace-vs-code\Powershell\ClonedRepos\"
Get-Content .\CloneAllRepos.config | ForEach-Object {
    $repoLocation = $localPath + $_.Split('/')[-1]
    Write-Host('Maven build for ' + $repoLocation)
    mvn -f $repoLocation clean install -DskipTests=true
    Write-Host('Maven build completed for ' + $repoLocation)
    $repoLocation = ''
}

0 个答案:

没有答案