通过Azure DevOps管道通过PowerShell脚本运行.jar,传递的参数在jar中无法识别

时间:2019-08-29 10:18:12

标签: java powershell azure-devops

我们有一个jar文件,它是通过从提供的位置解压缩文件夹开始的。该jar是通过PowerShell脚本在VM上启动的,该脚本本身是通过Azure DevOps发行任​​务“运行远程​​计算机的Powershell”启动的。该jar接受从管道发布时设置的参数通过PowerShell脚本传递的参数。其中两个参数是文件夹位置(输入和输出文件夹)。 问题是,当这通过DevOps发布管道运行时,jar崩溃,并在我们的Catch语句中出现错误“需要定义传入和传出数据文件夹。检查它们是否是有效路径”。 如果我们通过相同的参数在同一台VM上手动运行PowerShell脚本,则jar文件可以正常运行,并且可以轻松完成所需的一切。

jar将从PowerShell脚本接收到的参数注销到文本文件中,无论该脚本是通过管道还是通过手动启动日志在VM上运行,都表明传递了正确的args。 我在输出日志中的两个文件夹位置上都做了一个Dir,它将我带到正确的位置,这样就不会在某种程度上使它们失真。 VM登录的用户具有访问文件夹的权限,该用户与通过DevOps释放任务登录的用户相同。 VM正在运行Windows NT 6.2 我尝试使用相同的参数和相同的用户在该VM上通过Powershell运行脚本,并且工作正常。 我尝试围绕传递到“”中的args列表中的参数,以确保它们以字符串形式传递,这给出了相同的结果。

下面是运行jar的PowerShell脚本;

    Param(
    [Parameter (Mandatory = $true)]
    [string] $featureCounterFilePath,

    [Parameter (Mandatory = $true)]
    [string] $jarFileName,

    [Parameter (Mandatory = $true)]
    [string] $inputFilepath,

    [Parameter (Mandatory = $true)]
    [string] $outputFilepath,

    [Parameter (Mandatory = $true)]
    [string] $product,

    [Parameter (Mandatory = $true)]
    [string] $logging = "true"
)

$args = '-jar', "$featureCounterFilePath\$jarFileName", $inputFilepath, $outputFilepath, $product, $logging

$jarStart = Start-Process -FilePath java -ArgumentList $args -Wait

Java App的初始部分如下。通过DevOps发布管道运行时,它永远不会超过这一点,并且不会触到catch语句。

final String incomingFolderLocation;

        /** The folder to output temporary files, during analysis (Should be an empty folder) **/
        final String outgoingFolderLocation;

        final String productName;

        /** Defines whether every node should be output to a text file. true = output nodes to file. **/
        boolean outputlog = false;

        boolean clearSQLDB = true;

        logger.info("Parsing program arguments.");
        for (int i = 0; i < args.length; i++ ) {
            logger.info(args[i]);
        }
        // check first 2 arguments are existing files/folders
        if ((new File(args[0]).exists() && new File(args[1]).exists())) {
            incomingFolderLocation = args[0];
            outgoingFolderLocation = args[1];
            productName = args[2];

            try {
                if (args[3].toLowerCase().equals("true")) {
                    outputlog = true;
                }
                if(args[4].toLowerCase().equals("false")){
                    clearSQLDB = false;
                }
            } catch (IndexOutOfBoundsException e) {
            }
        } else {
            logger.error("Incoming or outgoing folder could not be found. Check they are valid");
            throw new IllegalArgumentException("The incoming and outgoing data folder needs to be defined. Check they are valid paths.");
        }

我希望应该发现路径存在,因为脚本/ jar正在使用同一用户在同一Vm上使用相同的参数运行,无论是手动运行还是通过管道运行。 感谢您的所有帮助和建议。

0 个答案:

没有答案
相关问题