2015-10-27 131 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

相關問題