与在构建步骤中执行时相比,在命令行中执行时脚本的结果如何不同

时间:2019-01-23 14:26:18

标签: oracle powershell jenkins-plugins

我有一个Powershell脚本,用于连接到Oracle数据库,我将从中查询某些字段。脚本开始如下:

        [System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient")

通过命令行执行时

        PS C:\Users\MyuserID\Documents\DBtest> .\DBtest.ps1

产生以下输出:

        GAC    Version        Location                                                                                         
        ---    -------        --------                                                                                         
        True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_64\System.Data.OracleClient\v4.0_4.0.0.0__b77a5c561934e0...

这之后是某些select语句,该语句可以按预期运行,并返回我们查询的行

但是,当我尝试通过在构建步骤中插入命令或在Jenkins构建步骤中执行相同命令时, 通过绝对路径调用它,我得到的结果是:

        Started by user MyuserID
        Building in workspace E:\Datapower\Jenkins\workspace\powershell_remote_execute
        [powershell_remote_execute] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'D:\TEMP\jenkins5910047931722903259.ps1'"

        GAC    Version        Location                                                 
        ---    -------        --------                                                 
        True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data.O...
        Exception calling "Open" with "0" argument(s): "Attempt to load Oracle client 
        libraries threw BadImageFormatException.  This problem will occur when running 
        in 64 bit mode with the 32 bit Oracle client components installed."
        At C:\Users\MyuserID\Documents\DBtest\DBtest.ps1:13 char:3
        +         $connection.Open()
        +         ~~~~~~~~~~~~~~~~~~
            + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
            + FullyQualifiedErrorId : InvalidOperationException



        Finished: SUCCESS

弄清楚Jenkins在打算选择64位时选择了要连接的32位二进制文​​件并不需要花费太多时间:

        GAC    Version        Location                                                 
        ---    -------        --------                                                 
        True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data.O... 

编辑:我没有明确调用x86可执行文件,我只是传递了该文件。 command 要么 filepath to the command

有人可以指导我了解如何解决此问题。

1 个答案:

答案 0 :(得分:0)

可以调用x86可执行文件吗?

而不是:

[powershell_remote_execute] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'D:\TEMP\jenkins5910047931722903259.ps1'"

尝试

[powershell_remote_execute] $ "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass" "& 'D:\TEMP\jenkins5910047931722903259.ps1'"