[英]Build step 'Windows PowerShell' marked build as failure, why?
Below are three PowerShell Commands run in Jenkins and the build result. 下面是在Jenkins中运行的三个PowerShell命令和构建结果。 Why it fails?
为什么失败? Which command could be failing?
哪个命令可能失败? I've read this post: How/When does Execute Shell mark a build as failure in Jenkins?
我已经阅读过这篇文章: 如何/何时执行Shell将构建标记为Jenkins中的失败? , but couldn't figure out.
,但无法弄清楚。 I am not familiar with MS stuffs.
我不熟悉MS的东西。
Command 1: 命令1:
& "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.com" "$env:WORKSPACE\ETL\OnePnL.sln" /Build
Command2: 命令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
}
Command 3: 命令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"
Build result: 构建结果:
[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
The answer is sort of in the post you linked. 答案就在您链接的帖子中。
the exit code of last command of the Jenkin's Execute Shell build step is what determines the success/failure of the Build Step
Jenkin的Execute Shell构建步骤的最后一个命令的退出代码决定了构建步骤的成功/失败
I get that you understand that much, but what makes it come into play is the return code for robocopy which was you last command. 我知道你了解那么多,但让它发挥作用的是robocopy的返回代码,这是你最后的命令。 While the link is for server 2008 I won't be surprised if they are OS common.
虽然该链接适用于服务器2008,但如果它们是OS常见的话我也不会感到惊讶。
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.
If all the files were copied successfully then the return code is 1. Anything other than 0 is reported as a failure by the build step as we have read in the linked question. 如果所有文件都已成功复制,则返回代码为1.除了0以外的任何内容都被构建步骤报告为失败,正如我们在链接问题中所读到的那样。
I think what you need to do is check the return code of robocopy and change it. 我认为您需要做的是检查robocopy的返回码并进行更改。
To check it you need to look at a PowerShell automatic variable $? 要检查它,你需要查看PowerShell自动变量$?
$?
$?
Contains the execution status of the last operation.包含上次操作的执行状态。 It contains TRUE if the last operation succeeded and FALSE if it failed.
如果上一次操作成功,则包含TRUE;如果失败,则包含FALSE。
So the last couple of lines could be... 所以最后几行可能是......
ROBOCOPY "$env:WORKSPACE\ETL\Project Type 0\bin\DEFAULT" "$outputdir" /E /v
If($?){exit 0}
What this should do is take any non zero result from robocopy and force the script to return true. 这应该做的是从robocopy获取任何非零结果并强制脚本返回true。 Again, be aware that this would return OK for all return codes.
再次,请注意,对于所有返回代码,这将返回OK。 If this is not desirable then you could easily build some logic for certain codes.
如果这不合适,那么您可以轻松地为某些代码构建一些逻辑。
I cannot really test this code as I do not have your environment but in theory it should work or at least get you started on where you need to be. 我无法真正测试这段代码,因为我没有你的环境,但理论上它应该可以工作,或者至少可以让你开始你需要的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.