当前位置: 首页 > 知识库问答 >
问题:

构建步骤“Windows PowerShell”标记为构建失败,为什么?

司马念
2023-03-14

下面是在Jenkins中运行的三个PowerShell命令和构建结果。为什么会失败?哪个命令可能会失败?我看过这个帖子:在Jenkins中,如何/何时执行Shell将一个构建标记为失败?,却想不出来。我对微软的东西不熟悉。

命令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

共有1个答案

长孙泉
2023-03-14

答案就在你链接的帖子中。

Jenkin的Execute Shell构建步骤的最后一个命令的退出代码决定了构建步骤的成功/失败

我知道你明白很多,但让它发挥作用的是 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自动变量$?

$?< br >包含最后一个操作的html" target="_blank">执行状态。如果上一次操作成功,则包含TRUE,如果失败,则包含FALSE。

最后几行可能是。。。

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

这应该做的是从机器人复制中获取任何非零结果,并强制脚本返回true。同样,请注意,这将为所有返回代码返回OK。如果这不可取,那么您可以轻松地为某些代码构建一些逻辑。

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

 类似资料:
  • Jenkins将良好的构建标记为失败,因为某些单元测试失败。如果我在没有单元测试的情况下运行构建,我将获得构建成功状态。如何配置Jenkins来执行以下操作:

  • 我正在尝试创建一个.so库,包含OpenCV C++代码。我设置了一些非常基本的东西--使用visual studio构建项目,使用“动态共享库(Android)”模板。 我从以下网址下载了Android OpenCV SDK:https://OpenCV.org/releases/ E0035#错误指令:此构造函数尚未移植到此平台文件:C:\microsoft\androidndk64\andr

  • 遵循下面的引导,在 Linux 上构建 Electron . Prerequisites Python 2.7.x. 一些发行版如 CentOS 仍然使用 Python 2.6.x ,所以或许需要 check 你的 Python 版本,使用 python -V. Node.js v0.12.x. 有很多方法来安装 Node. 可以从 Node.js下载原文件并且编译它 .也可以作为一个标准的用户在

  • 遵循下面的引导,在 Windows 上构建 Electron . 前提 Windows 7 / Server 2008 R2 or higher Visual Studio 2013 with Update 4 - download VS 2013 Community Edition for free. Python 2.7 Node.js Git 如果你现在还没有安装 Windows , mod

  • 遵循下面的步骤, 在 Windows 平台上构建 Electron。 Build Instructions (Windows) Follow the guidelines below for building Electron on Windows. 基本要求 Windows 10 / Server 2012 R2 或更高版本 Visual Studio 2017 15.7.2 或更高版本 - 免

  • 遵循下面的引导,在 macOS 上构建 Electron. Build Instructions (macOS) Follow the guidelines below for building Electron on macOS. 基本要求 macOS >= 10.11.6 Xcode >= 9.0.0 node.js (外部) 包含TLS 1.2支持的Python2.7 Prerequisit

  • 遵循下面的步骤,在 Linux 上构建 Electron. Build Instructions (Linux) Follow the guidelines below for building Electron on Linux. 前提条件 至少 25GB 硬盘空间 和 8GB 内存. Python 2.7.x. 一些发行版如 CentOS 6.x 仍然使用 Python 2.6.x ,所以或许

  • 按照下面的指南在Windows下构建 Electron 本身,以此创建自定义 Electron 二进制文件。 为了将您的应用代码与预构建的 Electron 二进制文件打包并发布,请参阅 应用程序发布 指南。 Prerequisites Windows 10 / Server 2012 R2 或更高版本 Visual Studio 2017 15.7.2 或更高版本 - 免费下载 VS 2019