0

So, there is always one installer (msi) in a folder for install generation, but the name changes many times. I tried doing the following:

"C:\Windows\system32\msiexec.exe" /i "C:\test\*.msi" /qn

But sadly, this doesn't work and complains. How can we get the name of the single msi in the folder, and plonk it into the command?

I'm using jenkins and using the "Execute windows batch command" item

uaswpff
  • 75
  • 6
  • Possible duplicate of [Batch - Write output of DIR to a variable](https://stackoverflow.com/questions/47450531/batch-write-output-of-dir-to-a-variable) – zett42 Nov 07 '19 at 17:49
  • The simple solution is: `for %%I in ("C:\Test\*.msi") do %SystemRoot%\System32\msiexec.exe /i "%%I" /qn` – Mofi Nov 07 '19 at 17:55
  • Change your 'Execute windows batch command', to either `"C:\Users\uaswpff\my folder\myscript.cmd"` or `Call "C:\Users\uaswpff\my folder\myscript.cmd"`, *(obviously you can change these names/paths to suit your particular environment)*. Then create `myscript.cmd` with the following content, `@For %%# In ("C:\Test\*.msi")Do @"%__AppDir__%msiexec.exe" /i "%%#" /qn`. – Compo Nov 07 '19 at 18:50
  • Hi Compo, not sure what you mean by change "Execute windows batch command". That's the little item you can create in jenkins to put your executable commands in there.... i wouldn't know how to create a script for jenkins to run without writing it in the execute windows batch command item – uaswpff Nov 07 '19 at 20:11
  • @uaswpff, I've told you what to put in the window under 'Execute windows batch command', and I've told you what to put in the batch file you've told Jenkins to run. Short of coming to your PC and doing it for you, I don't know what else I can offer you at this time because I've made it as simple as I can. – Compo Nov 07 '19 at 20:46
  • Don't worry. I understand what you mean now. I was hoping to not have to put a physical file on jenkins i.e. the script, so i'm gonna use the powershell plugin and do it from there. Thanks though – uaswpff Nov 07 '19 at 20:53
  • 1
    @uaswpff Use the command line posted by me in Jenkins. You don't need a batch file stored on hard disk. Jenkins writes the single command line as posted by me into a temporary created batch file on job execution, executes the batch file with `cmd.exe` and then deletes the batch file with that command line. – Mofi Nov 08 '19 at 06:52
  • sweet. good to know – uaswpff Nov 08 '19 at 10:18

1 Answers1

2

Perhaps use a for loop to find all .msi files in that directory, and run it accordingly (obviously if there is more than one .msi you will need to tweak this logic):

for /r "C:\test" %%a in (*.msi) do msiexec /i "%%~dpnxa" /qn
Captain_Planet
  • 1,228
  • 1
  • 12
  • 28
  • `%%~dpnxa` is the same as `%%~fa`. And it should be mentioned, that `/r` means "recursive", so it will execute all *.msi in the given folder *and all subfolders* – Stephan Nov 07 '19 at 18:19
  • Your current answer is providing a batch file solution, but that alone does not satisfy the question posed. Please note that the question states, `I'm using jenkins and using the "Execute windows batch command" item`. Take a look at my comment below the question, where I explain, what to put in the `Execute windows batch command` window entry, in order to run the batch file. – Compo Nov 07 '19 at 19:42