Running the batch file using gitlab ci and getting the output - batch-file

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.

Related

Jenkins Output Incomplete Log to the Console - SilkTest

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.

scheduling a bat file which uses rclone

I made a .BAT file which looks like this:
cd "C:\Portable Apps\rclone"
rclone mount Test: X:
What this does is mount a cloud storage location to my "X" drive. When I am double clicking this batch file everything works properly, but when I try to launch it through windows task scheduler nothing happens.
Note: I also tried to use a .EXE wrapper using a utility called "bat2exe", but nothing seems to work.
What did I do wrong...help would be greatly appreciated.
I SOLVED IT
Made a batch file with following:
cd "C:\Portable Apps\rclone"
rclone mount Test: X: --config C:\Users\MyUsername\.config\rclone\rclone.conf
Then I entered the following settings in windows scheduler:
Executed it and Behold it worked :))

Using Gitlab CI/CD to run command batch file

Using Gitlab CI/CD to run command batch file.
I have a batch file stored locally in my system. Now I want to run it from GitLab CI/CD YAML file.
I used the below format to run the YAML
Windows:
script:
- call: ci\CheckStatus.bat init
- call: ci\CheckStatus.bat build
tags:
- windows
But it is giving me below error
Found errors in your .gitlab-ci.yml:
jobs:windows:script config should be a string or an array containing strings and arrays of strings
How to resolve this and call my batch file to execute.
There is no call keyword under script so just enter executable commands as you would use them locally:
Windows:
script:
- ci\CheckStatus.bat init
- ci\CheckStatus.bat build
tags:
- windows

Writing Batch file that monitors a certain web page's status

The issue
I am trying to create a batch file that will execute the following two commands:
cd /some/path
dotnet run
that produces the following output:
It starts my localhost server.
Trying To Accomplish
What I would like to do is, put those two commands in a batch file and automatically open Chrome to the server address, HOWEVER, the dotnet command takes some time to finish. So somehow, I would have to keep monitoring localhost to see if it is available.
Any help would be appreciated. Although opening a CMD window, typing those 2 commands, and waiting a minute isn't all that much of a problem, it sure would be nice to just click on a batch file.
Thank you.
You can create a batch file like this code :
#echo off
Set "ApplicationPath=%UserProfile%\source\repos\PruttPos\PruttPosSystem\"
CD /D "%ApplicationPath%"
dotnet run
Start "Chrome" Chrome.exe "http://localhost:5000"
pause

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.

Resources