Javastatement in ps1 file is not executed as admin if mixed with other statements. (Error:Return argument has an invalid type)

huangapple 未分类评论46阅读模式
英文:

Javastatement in ps1 file is not executed as admin if mixed with other statements. (Error:Return argument has an invalid type)

问题

context:

我们尝试为 UFT 和 Selenium 执行配置运行时虚拟机(VM)。这些 VM 是基于 Citrix 的,在夜间重新启动,使用最新的生产镜像,并在此重新启动过程中失去其自动化配置。然后,一个定时任务以提升的权限执行 PowerShell 脚本,将一个 Jenkins 文件夹复制到 VM,下载用于连接的 Jenkins slave.jar,安装 UFT 和 Eclipse,最后开始连接到 Jenkins。

  1. 如果我以管理员身份启动 PowerShell 并手动执行命令,一切正常运行。

  2. 如果我将其放入 PowerShell 脚本文件中,并通过定时任务执行它,一切看起来都正常。但是,如果我通过 Jenkins 启动 UFT 测试用例,我的作业中会出现“返回参数具有无效类型”的错误。看起来连接没有以提升的权限启动。

  3. 如果我将脚本分成两部分,除了连接之外的所有步骤放在一个脚本中,连接放在第二个脚本中,测试用例就可以正常运行。

我已经将脚本重建为批处理文件,但行为完全相同。

因此,选项 3 可行,但 Citrix 管理员和我的领导对这种不可预测的行为感到不满。是否有人能够提示我们如何在一个 PowerShell 脚本中使脚本运行?

完整脚本(产生错误):

switch -wildcard($env:computername){
    "wxp-guirun-p*" {

        robocopy '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\VhvEntw' 'c:\VHVEntw' /E
   
		Invoke-WebRequest https://jenkins-master.ads.vhv.de/jnlpJars/slave.jar -OutFile c:\vhvEntw\Jenkins\slave.jar
	
        cscript '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\UFT_3811-000\14.0\Package\Wrapper\Default\Wrapper_64.vbs'
	
        Start-Process 'C:\Program Files (x86)\HP\Unified Functional Testing\bin\HP.UFT.LicenseInstall.exe' -Argument 'concurrent 20402 1 SERVERADRESS'
		
        cscript '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\eclipse_1685-000\4.10.0\Package\Wrapper\Default\Wrapper.vbs'
        
        break;
       }

}

echo $env:computername

switch -wildcard($env:computername){

    "wxp-guirun-p01" {
           java -jar c:\vhventw\jenkins\slave.jar -jnlpUrl SERVERADRESS AND SECRET -workDir "C:\vhvEntw\Jenkins"
            break;
       }
}

分成两部分后可以正常运行:

安装部分:

switch -wildcard($env:computername){
    "wxp-guirun-p*" {

        robocopy '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\VhvEntw' 'c:\VHVEntw' /E
   
		Invoke-WebRequest https://jenkins-master.ads.vhv.de/jnlpJars/slave.jar -OutFile c:\vhvEntw\Jenkins\slave.jar
	
        cscript '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\UFT_3811-000\14.0\Package\Wrapper\Default\Wrapper_64.vbs'
	
        Start-Process 'C:\Program Files (x86)\HP\Unified Functional Testing\bin\HP.UFT.LicenseInstall.exe' -Argument 'concurrent 20402 1 SERVERADRESS'
		
        cscript '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\eclipse_1685-000\4.10.0\Package\Wrapper\Default\Wrapper.vbs'
        
        break;
       }

}

连接部分:

echo $env:computername

switch -wildcard($env:computername){

    "wxp-guirun-p01" {
            java -jar c:\vhventw\jenkins\slave.jar -jnlpUrl SERVERADRESS AND SECRET -workDir "C:\vhvEntw\Jenkins"
            break;
       }
}
英文:

context:

We try to configure runner vms for UFT and Selenium execution. These vms are citrix based and restart at night with the most up to date productive image and lose their automation configuration in this restartprocess.. Then a sheduled task executes a powershellscript with elevated rights which copies a jenkinsfolder to the vm, download the jenkins slave.jar for the connection, installs uft and eclipse and at last starts connection to jenkins.

  1. If i start powershell as admin and execute the commands by hand everything works fine.

  2. If i put it into a powershell scriptfile and execute it with a sheduled Task it looks all fine. But i get a "Return argument has an invalid type" in my job if i start a UFT testcase via jenkins. It looks like the connection is no started with elevated rights.

  3. If i cut the script in half. All steps but the connection in one script and the connection in a second one, the testcase runs without any problems.

I rebuild the script in a batch file but is has the complete same behavior.

So option 3 is working but the citrix admins and my lead are not happy with such an unpredictable behavior. Does anyone has a hint how we can get the script running in one powershell script?

complete Scipt (produces the error):

switch -wildcard($env:computername){
    "wxp-guirun-p*" {

        robocopy '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\VhvEntw' 'c:\VHVEntw' /E
   
		Invoke-WebRequest https://jenkins-master.ads.vhv.de/jnlpJars/slave.jar -OutFile c:\vhvEntw\Jenkins\slave.jar
	
        cscript '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\UFT_3811-000\14.0\Package\Wrapper\Default\Wrapper_64.vbs'
	
        Start-Process 'C:\Program Files (x86)\HP\Unified Functional Testing\bin\HP.UFT.LicenseInstall.exe' -Argument 'concurrent 20402 1 SERVERADRESS'
		
        cscript '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\eclipse_1685-000\4.10.0\Package\Wrapper\Default\Wrapper.vbs'
        
        break;
       }

}

echo $env:computername

switch -wildcard($env:computername){

    "wxp-guirun-p01" {
           java -jar c:\vhventw\jenkins\slave.jar -jnlpUrl SERVERADRESS AND SECRET -workDir "C:\vhvEntw\Jenkins"
            break;
       }
}

Cut in half it works:

Installation:

switch -wildcard($env:computername){
    "wxp-guirun-p*" {

        robocopy '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\VhvEntw' 'c:\VHVEntw' /E
   
		Invoke-WebRequest https://jenkins-master.ads.vhv.de/jnlpJars/slave.jar -OutFile c:\vhvEntw\Jenkins\slave.jar
	
        cscript '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\UFT_3811-000\14.0\Package\Wrapper\Default\Wrapper_64.vbs'
	
        Start-Process 'C:\Program Files (x86)\HP\Unified Functional Testing\bin\HP.UFT.LicenseInstall.exe' -Argument 'concurrent 20402 1 SERVERADRESS'
		
        cscript '\\vhv\sachgebiete\Sachgebiete\Testautomatisierung\Installationsdateien\Runner\eclipse_1685-000\4.10.0\Package\Wrapper\Default\Wrapper.vbs'
        
        break;
       }

}

Connection:

echo $env:computername

switch -wildcard($env:computername){

    "wxp-guirun-p01" {
            java -jar c:\vhventw\jenkins\slave.jar -jnlpUrl SERVERADRESS AND SECRET -workDir "C:\vhvEntw\Jenkins"
            break;
       }
}

答案1

得分: 0

如果您的 UFT.exe 进程是使用 Quicktest.Automation COM 对象创建的,那么该进程将不会继承其父进程的任何内容(如提升的权限、处理程序、环境变量等)。它似乎是从用户上下文中启动的。

作为一种解决方法,您可以从命令行启动 UFT.exe 进程(禁用启动屏幕和插件选择),稍等片刻,然后再使用自动化对象连接到它。这样,UFT 将会继承您的环境变量和处理程序,以及父进程(Jenkins)的提升权限。

英文:

If your UFT.exe process is created using the Quicktest.Automation COM Object then the process will not inherit anything from it's parent process (like elevated rights, handlers, environment variables etc). It seems to be spinned of from the User Context.

As a Workaround you could start the UFT.exe process from the command Line (Disable Startup Screens and Add-In Selection), wait a bit and then connect to it with your Automation Object. In this way UFT will inherit your environment variables and handlers, and also the Elevated rights of the Parent Process (Jenkins)

huangapple
  • 本文由 发表于 2020年5月29日 19:15:29
  • 转载请务必保留本文链接:https://java.coder-hub.com/62084663.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定