Jenkins Output Incomplete Log to the Console - SilkTest - batch-file

I have a Jenkins pipeline that will run a batch file which contains command to run silk test. The part of the pipeline is as follow:
stage('execute-testscripts') {
steps {
script {
bat "cd Automation"
bat "C:\\Users\\Administrator\\Desktop\\silk_test.bat"
}
}
}
The content of silk_test.bat is as follow:
"C:\Program Files (x86)\Silk\SilkTest\ng\gui\STW.exe" -d examplexx -u example_id -p xxxxxx -r MY_EXAMPLE -s "ExampleXML" -verbose >> output.txt
type output.txt
del output.txt
When I execute the batch file on the command prompt on the Jenkins slave (via Remote Desktop Connection), the result is as follow (some details are hidden):
However, when I run the build on Jenkins, the console output is incomplete (doesn't show the output after the line "VERBOSE MODE: ON"):
[The same command is being run on the same Jenkins slave]
Is there any way to fix the Jenkins pipeline so that it displays the complete console output?

The issue is resolved by running the Jenkins slave agent as a Windows process, rather than running it as a Windows service, so that the process can interact with the applications.

Related

Running the batch file using gitlab ci and getting the output

I have set up my gitlab project with two files: one with a batch file which just prints hello world the other file is .gitlab-ci.yml file which executes the pipeline.
The code in the batch file is:
ECHO OFF
ECHO 'Hello World'
PAUSE
The gitlab-ci.yml file has the test stage:
test:
stage: test
script:
- echo 'test'
- chmod +x ./hello-world.bat
When I make any changes the pipeline starts and executes successfully, but I am not getting the required output from the batch file. I am missing something here?
The pipeline result looks like this:
As I am using the gitlab-ci runner on windows I created a python script and pushed that to the self-hosted github instance. In that python script, I just triggered the .bat script which then runs and shows the output in the project pipeline.
The script looks like this:
import subprocess
subprocess.call([r'C:\hello.bat'])
That is what I wanted.
From what I see, you're only adding +x permissions to the file making it executable, but never actually running it.
If you modify your gitlab-ci.yml to:
test:
stage: test
script:
- echo 'test'
- chmod +x ./hello-world.bat
- ./hello-world.bat
That being said, I'm not 100% sure this is going to work. Since this seems to be running on a linux system, and .bat scripts are intended for windows based systems.
Please refer to bash scripts on how these work.

how to run pass docker terminal commands using .bat file

I Want to invoke docker compose using bat file.I have tried to invoke using the following but its not executing the commands.
this is my .bat file
echo on
cd C:\Program Files\Docker Toolbox\
start start.sh cd desktop
cd test
docker-compose up
Is there any other way to execute docker commands using bat file.or any other file.
A batch file is a script file. A script needs an interpreter. For a batch file the interpreter is cmd.exe – the Windows command interpreter.
A *.sh file is also a script which needs an interpreter. The interpreter is on Unix/Linux systems sh, bash, ksh, ... which are also executables but without file extension .exe because on Unix/Linux executables usually do not have a file extension.
On Windows there is no interpreter installed by default for Unix/Linux shell scripts. If start start.sh works at all than because of having installed a shell interpreter on Windows which has been registered in Windows registry as application for opening *.sh files which means interpreting the commands in the shell script file by started application.
But commands in a batch script interpreted by cmd.exe and executed within a Windows command environment can't be executed in shell environment of the shell interpreter.
start start.sh starts a new process running parallel to the Windows command process created for execution of the batch file. The batch file processing immediately continues after this line with executing the next command in command process while the shell interpreter process interprets parallel the commands in start.sh.
So what you need here is a batch file which creates a shell script to call start.sh and executes other shell commands in shell environment by shell interpreter.
The batch code below might work. It is not tested by me as I don't have Docker Toolbox nor any shell interpreter installed on my Windows machine.
#echo off
set "ShellScriptFile=%TEMP%\%~n0.sh"
( echo start.sh
echo cd desktop/test
echo docker-compose up
) >"%ShellScriptFile%"
start "Docker Compose" /D"%ProgramFiles%\Docker Toolbox" /wait "%ShellScriptFile%"
del "%ShellScriptFile%"
set "ShellScriptFile="
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /? ... explains %~n0 (name of batch file without file extension and path)
del /?
echo /?
set /?
start /?
Read also the Microsoft article about Using Command Redirection Operators for an explanation of redirection operator > used here to create the shell script to execute with the 3 lines:
start.sh
cd desktop/test
docker-compose up
Those 3 lines are executed in the shell environment by shell script interpreter.
To run docker-compose via a bat file,
1. create a bat file eg run-docker-compose-up.bat
cd c:\docker
docker-compose up -d
pause
c:\docker is where I placed my docker-compose.yml
-d run containers in the background docker compose up docs
docker-compose must run as Administrator.
While a bat file itself cannot be marked as run as Administrator, you can either
right click on the bat file and choose 'Run as administrator'
or create a shortcut to the bat file and mark it as run as Administrator
(right click on shortcut, choose Properties, choose Advance, choose 'Run as administrator')
As I solved this problem, in a docker-compose case:
Go to your docker-compose.yml folder
On that, create a batchfile, such as: mydockerbatchfile.bat, using notepad (or other)
On this file, type your docker commands sequence', such as:
echo on
docker-compose down
docker container prune --force
docker system prune --volumes --force
docker image rm xxx/web-api
docker system df
docker image ls
pause
OBS: the commando pause will allow you check the results execution, in the screen)
Save -> make sure you saved in batch format/extension (mydockerbatchfile .bat)
In your windows desktop, create a ShortCut for the 'item 3 batch-file' (here - do not set the shortcut to "run as administrator")

why won't Jenkins write the ouput of my jmeter test to the specified logfile?

I have set up Jenkins to run my parameterized jmeter test (with the kind assistance of knowledgeable users here). I'm not using any other build technologies at the moment. I can run my tests and see the results in Jenkins as expected. However Jenkins is not writing the test data to my specified logfile. Here is my Windows batch script in Jenkins: C:\Users\MikeL\Documents\apache-jmeter\bin\jmeter.bat -n -t C:\Users\MikeL\Documents\apache-jmeter\bin\testApp.jmx -l log.jtl -Jenv=%env% -JloopCount=%loopCount% if I run jmeter -n -t testApp.jmx -l log.jtl -Jenv=dev -JloopCount=1 from the windows cmd prompt inside of jmeters bin dir It does create the log file as expected. If anyone knows why the Jenkins script won't output it I'd be very obliged.

How i can run a default browser from .bat file

I create a PHP server instance and I would like to run browser automatically with running run.bat
Bat file content:
"php/php.exe" -S localhost:81 -t dokuwiki
Just write folowing...
start website_address

MSBuild PSExec hangs without error while executing batch file

As part of as our Team Build MSBuild script, we have a deployment batch file which I need to execute on a remote server:
<Exec Command="psexec -accepteula \\servername D:\Build_Drop\DeploySites.bat "/>
I can confirm it is not permissions or firewall: if the bat command is changed to run iisreset or calc.exe for example, the command will work.
I have tried -s and >nul flags, and also wrapping the batch file in a call to cmd. I have tried with and without quotes around the bat cmd.
All the options I have tried will work fine from the cmd line on the build server, but none will work from within the build script itself.
Any ideas?
Adding a -i parameter to psexec seems to have worked.
Oddly, we now get the error message:
The command "psexec -accepteula \\server -i cmd /c "D:\Build_Drop\DeploySites.bat"" exited with code 5. Please verify that you have sufficient rights to run this command.
But the command does actually work

Resources