groovy (java): exec() do not detach from process (Intellij IDEA vs Maven+TestNG) - maven-2

I have Groovy Maven2 test project with TestNG and Surefire plugin enabled.
I want to launch external process (*.cmd file which start some *.exe file) in last test method, finish my tests and left process running after tests.
I tried the following codes to do it:
1 attempt
def builder = new ProcessBuilder('cmd','/c <name>.cmd')
builder.directory( ( new File( <path_to_working_directory> ) ) )
builder.start()
2 attempt (with and without start cmd option)
Runtime.getRuntime().exec( "cmd /c start <name>.cmd", null , ( new File( <path_to_working_directory> ) ) )
3 attempt
( new AntBuilder() ).exec(
dir: "<path_to_working_directory>",
executable: "<name>.cmd"
)
Where .cmd is:
set path=<path_to_execFile>;%path%
start <execFileName>.exe
When I launch each of these codes from Intellij IDEA via 'Run' functionality (Alt+Shift+F10) codes execute successfully, process started and run after test finishes.
When I launch each of these codes both from Intellij IDEA Maven task, clean Maven installation (and even Maven task from Jenkins) process started successfully but test remains running. I need to kill it manually. When I kill test process (Maven process) manually my launched external process continue to work as I expect.
This hung test process is my headache for the moment.
I looked through a lot of materials but didn't find any root cause, fix and even workaround for this issue. I see that all my attempts (perhaps, except of AntBuilder()) create deattached processes. I suppose that this can be connected with JVM settings. But I coudnl't find to which one.
Also, I tried
"full command to run my cmd".execute()
but it didn't help me too.
Could you please help me resolve the issue?
Thanks In Advance!

So, I do not see any answers for my issue here. But I have some updates.
I found that I can use PsExec tool instead of direct cmd calling:
def builder = new ProcessBuilder( 'psexec', 'cmd', '/c', '<name>.cmd' )
builder.directory( ( new File( <path_to_working_directory> ) ) )
builder.start()
And this code works fine when I launch it from clean Maven only (not from Jenkins): process started, Maven task completes successfully, the process continues to run.
But during execute this code as part of some Maven2 Jenkins task I faced to issue again: psexec started but Jenkins task is running and my process does not started before I terminate Jenkins task manually.
To avoid this issue I created simple additional Groovy service script I launch in listen mode (and Writing a TCP Server) on target machine manually during initial machine preparation. This script is running on machine always.
I send to this listener name of command file to execute from my test I launch from Jenkins and it executes all cmds successfully: processes start, Jenkins task completes successfully, processes continue to run. I use processbuilder inside this listener.
For name sending I use simple socket (Writing a TCP Client)
Also, I found how to detach child from process tree on win32?. But for me system my way looks more Groovy I think.

Related

Start IntelliJ run-configuration from command line

I work on a Kotlin-based cloud microservice. From time to time I need to run it in the IntelliJ debugger, but we often accidentally break the "local debug flow". There is no pipeline that checks if the IntelliJ run-configuration and the somewhat complex set of cloud-simulating proxies and mock-servers are in sync with the code base.
I would like to write a script that helps me check if the local debug flow works. The script should do the following:
build the project
start up the "mock cloud"
start the service locally using an IntelliJ run-configuration
run a Postman-collection against the locally running service
I need help with step 3 (and possibly step 1): How can I start the IntelliJ run-configuration via command line? I am using IntelliJ IDEA 2021.2 and MacOS 12.3.1.
There is no built-in way to start a Run Configuration from the command line. Instead, you should execute java/kotlin binary with classpath etc.
For example, for "Application" configuration it is needed to run the command like that:

Unable to add External Tool to run Before Configuration Launch IntelliJ

Introduction
I've looked around and haven't seen anyone else having my issue.
Basically, I am wanting to run a start.bat file to start up my server before I start up my debugging session. I currently have my debugging inside of an IntelliJ Configuration and it works well. The problem is that in the options for my configuration I can't seem to add an "External Tools" task to the Before Launch section. I was able to add a maven task here previously. However, when I follow the following steps, the "start.bat" is not added.
First I go into Settings->Tools->External Tools to add my Spigot-Server tool which basically calls the start.bat file inside of a test-server directory.
Snippet of External Tools
Second, I go into my "Debug Spigot" configuration and at the bottom, I see a "Before Launch" Section.
Snippet of Spigot Debug options
I click on the + inside of that section to add a new task, and I click on "External Tools"
Snippet of adding External Tools Task
And then I make sure my Spigot-Server task is selected.
Snippet of select external tool
And then once I hit okay, the window closes but I don't see a new task added to the before launch section. It looks the same it did before I clicked on anything. I also don't see any status message at the bottom of IntelliJ
I basically expect the task "Spigot-Server" to show under the Before Launch section. This would basically start up the server and once the server was completely started, it would then launch the debugging configuration.
I think it may be an issue with IntelliJ's UI. I searched IntelliJ's issue tracker But couldn't find any that matched.
I'm wanting to know if there are any work arounds to get this setup in IntelliJ>
I was able to achieve my goal by doing some workarounds that I discovered with the help of CrazyCoder. I found this stackoverflow question that told me about the batch plugin.
I was able to create a Batch run configuration for a wrapper batch file that gets around the limitation CrazyCoder mentioned. He said that even if I did get my setup where my server runs before my debugging is launched, my debugging would never launch. This is because the terminal process needs to exit before the next task starts.
To get around this this is the wrapper batch file I created.
#echo OFF
START "Spigot-Server" /D C:\Users\rocke\Documents\Programming\Minecraft\Spigot\capture-the-carrot\test-server "start.bat"
ping -n 3 127.0.0.1 >nul
It basically uses the "START" command to run the task asynchronously and then waits 2 seconds. This is because all I need to do is wait for the start.bat command to run the very first part so that it establishes remote debugging. And then the wrapper ends after 2 seconds (the 3 represents the number of seconds I want to wait +1). And this allows the Debugging process to start while also ensuring that the server has setup remote debugging!
I'll just share screenshots of my configuration if anyone wants to do the same.
Maven Build Configuration
Spigot Server Start Configuration
Remote Debugging Configuration
The way this is setup is once I run the Remote Debugging Configuration, it has a "Before Launch" Task of Spigot Server. Spigot Server also has a "Before Launch" Task of Maven Build Project.
So my Maven Build Project runs, then my Spigot Server wrapper runs and after 2 seconds terminates, and then my Debugging Configuration runs!
If you have any questions regarding remote debugging with spigot, use this resource: https://www.spigotmc.org/wiki/intellij-debug-your-plugin/

can't trigger a test of some appllication via Jenkins job

I am a beginner at the field of Devops.
I have created a simple web application (jsp), using 3 Jenkins jobs to store the code in GIT, to deploy the this app into Tomcat, and also to site-monitor this app (respectively).
Now, I have been trying - with no success -to automate a simple test with 2 verifications of my app functionality, using Selenium IDE and triggering it via Jenkins job (the fourth one in my project).
In order to perform it , I created the following job on Jenkins, with the needed plugin added (which is SeleniumHQ htmlsuite Run).
Here is the job:
https://i.stack.imgur.com/6Pm6a.png
The job running has failed,giving the following error which I cant handle.
When I run it, I get the following error :
https://i.stack.imgur.com/hXGmI.png
Any help would be very appreciated
Just tick Delete workspace before build starts box under Build Environment stanza
If you don't have the option in your Jenkins job configuration - make sure that Workspace Cleanup Plugin is installed
If you're running your Selenium tests via Jenkins Pipeline - all you need to do is to put cleanWS() directive somewhere in your pipeline code or Jenkinsfile

Is there a way to run command lines asynchronously in Azure-DevOps Build Pipeline?

I'm setting up an Azure-DevOps pipeline in which I want to include automated tests via the Newman CLI.
Imagine a pipeline like this.
Build Project
Copy build to test folder
Run the application => (API-Server)
Run Newman
Kill API Server Process
On Success Copy Build to another folder.
My Problem is that my server application is in a waiting state after it's initialization.
The next Task in my build pipeline won't start.
Is there a way to run multiple command lines asynchronously in Azure-DevOps?
Starting the process in via "start" won't work since it throws me an
ERROR: Input redirection is not supported, exiting the process immediately.
start "%TESTDIR%\foo\bar.exe"
timeout 10

Start program via ssh in Jenkins and using it in Jenkins build

Hello people.
I'm using Jenkins as CI server and I need to run some performance test using Jmeter. I've setup the plugin and configured my workspace and everything works ok, but I have to do some steps manually and I want a bit more of "automation".
Currently i have some small programs in a remote server. These programs make some specific validations, for instance (just to explain): validates e-mail addresses, phone numbers, etc.
So, before I run the build in jenkins, I have to manually start the program (file.sh) I want:
I have to use putty (or any othe ssh client) to conect to the server and then run, for instance, the command
./email_validation.sh
And the Jmeter test runs in a correct way, and when the test is done I have to manually "shut down" the program I started. But what I want is trying to start the program I need in Jenkins configuration (not manually outside Jenkins, but in "execute shell" or "execute remote shell using ssh" build step).
I have tried to start it, but it get stuck, because when Jenkins build finds the command
./email_validation.sh
the build stops, it waits for the command to finish and then it will continue the other build steps, but obviously, I need this step not to finish until the test is executed.
Is there a way to achieve this? Thanks
Run your command as a background process by adding the & symbol at the end of the command and use the nohup command in case the parent process gets a hangup signal, e.g.
nohup /path/to/email_validation.sh &
If the script produces any output, it will go by default to the file nohup.out in the current directory when the script was launched.
You can kill the process at the end of the build by running:
pkill email_validation.sh