我试图在VSTS管道中使用PowerShell在azure VM上运行Apache jMeter。问题是azure VM是新创建的,默认情况下没有安装JDK。由于jMeter需要'java',因此它抛出以下错误。
C:\apache-jmeter-5.2.1\bin>jmeter -n -t C:\User-search.jmx -l C:\
Not able to find Java executable or version. Please check your Java installation.
errorlevel=2
我需要在运行jMeter之前安装Java。有什么方法可以使用Powershell远程安装Java?
还是预装的Java是否有Windows Azure虚拟机映像可用?
首先与虚拟机建立会话,然后运行以下脚本。
#Download and silent install JDK
#Working directory path
Write-Host "Creating temp working directory..."
$workd = "c:\temp"
#Check if work directory exists if not create it
If (!(Test-Path -Path $workd -PathType Container))
{
New-Item -Path $workd -ItemType directory
}
#Create config file for silent install
Write-Host "Creating config file for silent install..."
$text = '
INSTALL_SILENT=Enable
AUTO_UPDATE=Enable
SPONSORS=Disable
REMOVEOUTOFDATEJRES=1
'
$text | Set-Content "$workd\jdkinstall.cfg"
#Download executable file
Write-Host "Download JDK file to temp directory..."
$source = "https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_windows-x64_bin.exe"
$destination = "$workd\jdk-13.0.2_windows-x64_bin.exe"
$client = New-Object System.Net.WebClient
$cookie = "oraclelicense=accept-securebackup-cookie"
$client.Headers.Add([System.Net.HttpRequestHeader]::Cookie, $cookie)
$client.DownloadFile($source, $destination)
Write-Host "Download JDK file completed !"
#Install silently
Write-Host "Trying to install JDK silently..."
Start-Process -FilePath "$workd\jdk-13.0.2_windows-x64_bin.exe" -ArgumentList INSTALLCFG="$workd\jdkinstall.cfg" -Wait
Write-Host "JDK installation completed successfully !"
#Remove the installer
Write-Host "Trying to remove JDK file from temp directory..."
rm -Force $workd\jdk*
Write-Host "JDK file deleted successfully !"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句