Batch-file to update files from SVN and then run a program - batch-file

Currently am executing a program from command prompt, basically a Python command, but I want that to be automated so that the program runs the latest version of the files before the program starts.
So current program is run by saying:
python c:\program\mysoftwareUI.py
mysoftwareUI.py is present in folder that constantly is provided with updates
Now I want to write a batch file with the above command but before that also SVN command that updates the folder before the actual program is run.
How can I do this?

Create a .bat file script and place it into a directory that is in the PATH variable or the current working directory.
=== doit.bat
#ECHO OFF
PUSHD "c:\program"
svn up
python c:\program\mysoftwareUI.py
POPD
EXIT /B

Related

Jenkins not able to run Poetry in batch file. Works when run manually

I'm attempting to get Jenkins to run a .bat file which contains a call to Poetry (for package management).
However, when running this .bat file via Jenkins, I'm getting a "'poetry' is not recognized as an internal or external command, operable program or batch file." error.
I believe this is due to the .bat file failing when it attempts to run a "call poetry check" command.
The .bat file runs successfully when run manually.
Is there some obvious feature of Jenkins that I'm missing here?
I'm aware that there is an alternative method of embedding poetry into Jenkins with direct commands. However this project is about to be passed on to someone else, and they would not be able to maintain that.
I've reproduced the key code below (the Jenkins code calling the .bat file, the code in the .bat file and the error output from Jenkins).
Jenkins code (standard pipeline with default settings):
pipeline {
agent any
stages {
stage('Main') {
steps {
bat 'E:\\project-folder\\project_run.bat'
}
}
}
}
Bat file code:
#echo off
cd /d "E:\project-folder\"
call poetry check && (
echo poetry checked
) || (
echo Problem with poetry
EXIT /B
)
echo Installing prod packages
call poetry install --no-dev && (
echo Production packages successfully installed
) || (
echo Problem installing packages to environment
EXIT /B
)
call python local-program.py
EXIT /B
)
Jenkins Error:
C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace[Pipeline_Name]>E:\project-folder\project_run.bat
Moving to project directory
'poetry' is not recognized as an internal or external command,
operable program or batch file.
Problem with poetry
Windows is looking up executables on the path you specify. If you run a command without a path, Windows looks for the command/executable in all directories specified in the environment variable PATH.
Very likely your Jenkins is running with different path settings than your interactive shell.
What you can do:
specify the full path to the command you want to raise in Jenkins
set the PATH variable in the Jenkins job prior to running the command
set the PATH variable before invoking Jenkins
Apart from the directory, Windows also has to check extensions. If you run poetry, Windows may have to find poetry.com, poetry.exe, poetry.bat or poetry.cmd. I suspect one of these files reside in E:\project-folder. To understand which files Windows checks for and the preference, have a look at the environment variable PATHEXT.
So to better understand these differences you can run the command set without parameters. Do that on the command line, and add the same command into your Jenkins job.

How to specify in windows batch file to open spyder, change the working directory and run a script?

I have created a windows batch file to run a code which is located in a particular folder. However, I am running the batch file but it does not work. What I want it to do is:
Change working directory in Spyder (Spyder is already openned so I don't want it to open it first)
Run the script I want to execute
Basically, the script I am running is plotting a bunch of graphs and all the files needed to create this are located in the working directory.
#echo off
"C:\Users\Mason\Desktop\WinPython-64bit-2.7.6.4\spyder.exe"
chdir /D "F:\optimisation"
"F:\optimisation\plot.py"
pause
The batch file runs fine without any errors, but nothing happens in Spyder e.g. it doesn't change the working directory and neither executes the code.
I'd suggest
#echo off
setlocal
chdir /D "F:\optimisation"
"C:\Users\Mason\Desktop\WinPython-64bit-2.7.6.4\spyder.exe" "F:\optimisation\plot.py"
pause
That is, switch to the required directory, having set a local environment (this restores the original environment when the batch terminates).
Then run the spyder executable, providing it with the name of the file. It would be normal practice to use this structure to provide a significant filename to an executable (eg notepad fred,txt)
Since the current directory when spyder runs is f:\optimisation, it is probably not necessary to specify the entire path in spyder's argument.
Note this is all just speculation using normal practice. I have no experience of spyder- in fact, this is the first I've heard of it.

Command Line Installation with SCCM 2012

I have a few applications that I am trying to deploy with SCCM 2012 but the installations are failing through the application catalog. So what I have for the deployment type is a script installer. I have "cmd.exe" (Without quotations) in the Installation program field and "Installer.bat" in the installation start in field.
When I look at the ccmcache folder, all the contents over that application are there but the following error displays the Software Center:
0x8007010B(-217024629)
I have done some reading online and the "10B" is a common command line error for invalid directory. I have tested the batch file when hard coding a path but my question is, how can I edit the batch file or SCCM to pull from the CCMCache path where the files are downloaded to on the local client? Currently the Batch File is simply:
#echo off
ApplicationName.exe
Do I need to edit the file to cd into the CCMCache folder where the files are placed? How can I get the batch file to run the executable that is downloaded to the CCMCache folder?
Thank You!
You need to have the full path to the installation in your script
#echo Off
\\path to .exe
The way the command is written will not be able to find the .exe file. You need to add the full unc path to the .exe into your .cmd file. You should have your installation .exe and .cmd file in the same location on the distribution share
Recommended Solution:
Before starting, since you are only launching an exe with your batch file, I would recommend just using your ApplicationName.exe as your command line parameter in SCCM instead of using a batch. This will eliminate the need to engineer any further.
Modifying the existing solution to work:
If you do still want to use a batch file, keep a few things in mind. The syntax you are using to launch the batch file will not work. I would recommend just using the batch file name "installer.bat" as your command line. If you still want to preface the batch with the cmd.exe, you absolutely need to use the /c switch with it
cmd.exe /c installer.bat
If you don't use /c the console host will only open to a promopt and not execute your batch.
This is not an ideal solution though because using "cmd.exe /c" will set your working directory to the location of cmd.exe (ie "C:\windows\system32") and since your content is staged in ccmcache, you will need to specify its location within your batch. To do this, you would use %~dp0 variable which gives you the directory the current batch is running from. This means modifying your batch to read
#echo off
%~dp0ApplicationName.exe

Change directory from batch file in Far console

The command
cd %SOME_DIR%
in Far console changes current directory.
But executing the same command in batch script from Far does nothing. Is it possible to switch directory using batch script in Far?
Far manager runs a batch script (.bat) in a child process and cd command only modifies the environment of the current process. It can't touch the environment of the parent.

Nunit result xml is not updated during Jenkins build

I have configured NUnit tests to run after build completed.(Jenkins)
I added following on Excecute windows batch command window in Jenkins.
rmdir ClickOnceInstall /Q /S
mkdir ClickOnceInstall
CD BuildScripts
Start.bat
"C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-console-x86.exe" AA.Tests\bin\x86\Release\AA.Tests.dll /xml=nunit-result.xml
It seems Execute unit test command doesn't create result file as specified name and marked as failed. However, when I run the nunit test command manually it creates the file. Next time build through Jenkins, result xml file does not seem to be updated but it doesn't fail.
am I missing any configuration or something else?
It would help if you would paste the console log.
However, my first guess is to ask you to add call to your batch file statement:
call Start.bat
If that batch file has an exit /b statement (even with 0), it will quit the whole calling step (i.e. "Execute windows batch command") without getting to your last statement (i.e nunit command).
Using call in front of the batch file will make sure that control is returned to the calling step.

Resources