1

I am trying to run the Apache jMeter on azure VM using PowerShell in VSTS pipeline. The problem is azure VM is newly created and there is no JDK installed by default. As jMeter requires 'java' so it throws below error.

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

I need to install the java before running the jMeter. Is there any way to install java remotely using Powershell?

Or if there is any windows azure VM image available with pre-installed java?

2 Answers 2

1

First make a session to the VM then run the below script.

#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 !"
Sign up to request clarification or add additional context in comments.

Comments

0

You can execute arbitrary commands on whatever machines using Powershell Remoting, the easiest way of installing Java Runtime is using Chocolatey package manager which should be as simple as:

choco install javaruntime -y

References:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.