2015-10-27 132 views
2

下面是在Jenkins中运行的三个PowerShell命令和构建结果。为什么失败?哪个命令可能失败?我读过这篇文章:How/When does Execute Shell mark a build as failure in Jenkins?,但无法弄清楚。我不熟悉MS的东西。构建步骤'Windows PowerShell'标记为失败,为什么?

命令1:

& "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.com" "$env:WORKSPACE\ETL\OnePnL.sln" /Build 

命令2:

########################### 
# Deploy SSIS package   # 
########################### 
$csource ="$env:WORKSPACE\ETL\Project Type 0\bin\DEFAULT\OnePnL.ispac" 
$cserver = "SSASDBDEV01" 
$cdest = "/SSISDB/OnePnL/OnePnL"  
echo $env:GIT_BRANCH  
if ($env:GIT_BRANCH -like '*master*') 
{ 
    # Call IS Deployment Wizard 
    echo "Deploying SSIS package to $cdest on $cserver"  
    # "C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\ISDeploymentWizard.exe" "/Silent /SourcePath:""$csource"" #/DestinationPath:""$cdest"" /DestinationServer:""$cserver""" -Wait 
    Start-Process "C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\ISDeploymentWizard.exe" "/Silent /SourcePath:""$csource"" /DestinationPath:""$cdest"" /DestinationServer:""$cserver""" -Wait 
} 

命令3:

##################### 
# Copy Files to O: drive # 
##################### 

#Make build directory 

#$outputparentdir = "\\orion\Shared\AppUpload\ApplicationPackage\OnePnL Cube\SSIS Jenkins Builds" 
$outputparentdir = "\\inv\Shared\Transfer - Deleted Weekly\Jenkins\BI\OnePnL\SSIS Jenkins builds" 
$outputdir = "$outputparentdir\${env:GIT_BRANCH}\Build ${env:BUILD_NUMBER}" 
echo "Branch" 
echo ${env:GIT_BRANCH} 

echo "Output directory" 
echo $outputdir 

if (!(Test-Path "$outputparentdir")) 
{ 
    mkdir $outputparentdir 
} 

mkdir $outputdir 

ROBOCOPY "$env:WORKSPACE\ETL\Project Type 0\bin\DEFAULT" "$outputdir" /E /v 

echo "Done Copy" 

生成结果:

[OnePnL SSIS] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\SVC_TE~1\AppData\Local\Temp\hudson3790190217372968147.ps1'" 

Microsoft (R) Microsoft Visual Studio 2012 Version 11.0.50727.1. 
Copyright (C) Microsoft Corp. All rights reserved. 
------ Build started: Project: OnePnL, Configuration: DEFAULT ------ 
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ========== 
[OnePnL SSIS] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\SVC_TE~1\AppData\Local\Temp\hudson2769520726749517170.ps1'" 
origin/release 
[OnePnL SSIS] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\SVC_TE~1\AppData\Local\Temp\hudson7860003244522954499.ps1'" 
Branch 
origin/release 
Output directory 
\\inv\Shared\Transfer - Deleted Weekly\Jenkins\BI\OnePnL\SSIS Jenkins builds\origin/release\Build 74 


    Directory: \\inv\Shared\Transfer - Deleted Weekly\Jenkins\BI\OnePnL\SSIS 
    Jenkins builds\origin\release 


Mode    LastWriteTime  Length Name        
----    -------------  ------ ----        
d----  10/26/2015 4:29 PM   Build 74       

------------------------------------------------------------------------------- 
    ROBOCOPY  ::  Robust File Copy for Windows        
------------------------------------------------------------------------------- 

    Started : Monday, October 26, 2015 4:29:01 PM 
    Source : D:\te_jenprodslave_1\workspace\Trade_Efficiencies\BI\OnePnL SSIS\ETL\Project Type 0\bin\DEFAULT\ 
    Dest : \\inv\Shared\Transfer - Deleted Weekly\Jenkins\BI\OnePnL\SSIS Jenkins builds\origin\release\Build 74\ 

    Files : *.* 

    Options : *.* /V /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 

------------------------------------------------------------------------------ 

         1 D:\te_jenprodslave_1\workspace\Trade_Efficiencies\BI\OnePnL SSIS\ETL\Project Type 0\bin\DEFAULT\ 
     New File   516475 OnePnL.ispac 
    0% 
25% 
50% 
76% 
100% 

------------------------------------------------------------------------------ 

       Total Copied Skipped Mismatch FAILED Extras 
    Dirs :   1   0   0   0   0   0 
    Files :   1   1   0   0   0   0 
    Bytes : 504.3 k 504.3 k   0   0   0   0 
    Times : 0:00:00 0:00:00      0:00:00 0:00:00 


    Speed :   43039583 Bytes/sec. 
    Speed :   2462.744 MegaBytes/min. 
    Ended : Monday, October 26, 2015 4:29:01 PM 

Done Copy 


Build step 'Windows PowerShell' marked build as failure 
+0

要求社区调试你的代码,而不是给他们提示这个问题通常与downvotes相关。我知道你对MS的东西不熟悉,但这意味着你只需要至少尝试一下自己就可以了。 – Matt

+0

它总是很高兴让回答者知道它工作或没有工作 – OK999

回答

3

答案就在你链接的文章中。

的最后一个命令的退出代码詹的执行shell建设步骤是什么决定了生成步骤的成功/失败

我让你了解那么多,但是什么使得它进场是return code for robocopy这是你最后的命令。虽然链接是为服务器2008年,我不会感到惊讶,如果他们是操作系统常见的。

Value Description 
0  No files were copied. No failure was encountered. No files were mismatched. The files already exist in the destination directory; therefore, the copy operation was skipped. 
1  All files were copied successfully. 

如果所有的文件都复制成功则返回代码为1 任何将0以外的报告为构建步骤失败,因为我们在链接的问题已经阅读。


我认为您需要做的是检查robocopy的返回码并更改它。

要检查它,你需要看一下PowerShell automatic variable $?

$?
包含上次操作的执行状态。它包含 如果上次操作成功则为TRUE,如果失败则包含FALSE。

所以,最后几行可能是......

ROBOCOPY "$env:WORKSPACE\ETL\Project Type 0\bin\DEFAULT" "$outputdir" /E /v 
If($?){exit 0} 

这是什么应该做的是从ROBOCOPY采取任何非零结果,并迫使脚本返回true。再次,请注意,这将返回所有返回代码的OK。如果这不可取,那么你可以轻松地为某些代码建立一些逻辑。

我无法真正测试此代码,因为我没有您的环境,但理论上它应该工作或至少让您开始您需要的位置。

+0

[PSDeploy](https://github.com/RamblingCookieMonster/PSDeploy)文件共享提供程序使用Robocopy,这解决了我在Jenkins的构建问题。即使PsDeploy包装robocopy退出代码并且函数成功,Jenkins仍然无法从内部robocopy的非零成功退出代码构建... – BenH

相关问题