Potential problem from Gitlab runner pipeline on windows (powershell)

Dear All
I have encountered some problems with gitlab pipeline script which composed by powershell executor..
I appreciated whoever experienced with this kind of problem comment anything that I could try...
There is no error in command log when I run this pipeline, however matlab.exe seems not operating actually...
# stage
stages:
- command
mfile_command:
stage: command
tags: [my-runner-windows-]
only:
- main
script:
- 'C:\"Program Files"\MATLAB\R2023b\bin\matlab.exe'
- powershell -command "Start-Sleep -Seconds 60"

4 Commenti

  1. What is the purpose of running MATLAB Desktop with command, and why GitLab?
  2. What do you mean by "however matlab.exe seems not operating actually..."? Can you elaborate the issue?
  1. My final purpose is running .m file script by pipeline: when I commit my model to repository. I knew that Gitlab tool has supported more security service than any others, and there is an issue which recommend to use Gitlab in my company group.
  2. When I launched the pipeline script above, no error appears in log which is presented when I clicked the piepline result. I expected that matlab.exe would operate and can see matlab command window in my monitor of course, but it was not.
(1) Would you mind taking a look at the answer below?
In short, try the below:
script:
- 'powershell.exe "C:\Program Files\MATLAB\R2023b\bin\matlab.exe"'
(2) If you want to run a script with MATLAB from command window, you can use "-r" option. For example, if you want to run myscript.m via command,
script:
- 'powershell.exe "C:\Program Files"\MATLAB\R2023b\bin\matlab.exe" -r myscript'
More information can be found from the doc below.
Thanks for reply.
I fixed my script as you recommended, but got an error:
$ powershell.exe "C:\Program Files\MATLAB\R2023b\bin\matlab.exe"
17C:\Program : The term 'C:\Program' is not recognized as the name of a cmdlet, function, script file, or operable progra
18m. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
19At line:1 char:1
20+ C:\Program Files\MATLAB\R2023b\bin\matlab.exe
21+ ~~~~~~~~~~
22 + CategoryInfo : ObjectNotFound: (C:\Program:String) [], CommandNotFoundException
23 + FullyQualifiedErrorId : CommandNotFoundExceptio
Instead, I wrote my script as below :
script:
- powershell.exe "& 'C:\Program Files\MATLAB\R2023b\bin\matlab.exe'"
Yet I could not execute matlab.exe ....

Accedi per commentare.

Risposte (3)

Hi,
A possible cause of such errors in powershell is because of spaces present in the path of executable you are trying to execute. As a workaround you can refer these steps:
  • Firstly execute cd '<Path to the bin folder containing the .exe of MATLAB>' in Windows Powershell. Entire path should be in single qoutes.
  • Then you can execute this command powershell matlab.exe -r myscript, which would launch MATLAB.
Hope it helps!

1 Commento

Thank you for you reply
Of course, I normally execute my matlab.exe when I command on Powershell prompt directly.
The point is that I could not see same results despite of any errors on build log under gitlab runner pipeline.
My script was written as below:
script:
- echo "script start!!!" # Test
- cd 'C:\Program Files\MATLAB\R2023b\bin\'
- ls # Check path was normally entered
- matlab.exe
Best regards

Accedi per commentare.

I had to use the following to force the gitlab runner to "wait" on MATLAB

matlab -batch "myBuildScript" -wait

Otherwise the gitlab script would timeout and fail even through there were no MATLAB errors.

3 Commenti

Thanks for replying, then should I fix the script as below? I just want to know the Matlab normally open in my window.
script:
- echo "script start!!!" # Test
- cd 'C:\Program Files\MATLAB\R2023b\bin\'
- ls
- matlab.exe - wait
Do you want to open MATLAB and have the desktop window display or are you looking to run the pipeline in batch mode?
This documenation might help to answer yours and my question.
The former is that I am trying,
Thank you for your recommand, however the pipeline was stopped(not proceed) when I add 'wait' in my script
because my desktop could not handle this command I thought.

Accedi per commentare.

Ben
Ben il 22 Apr 2025
Modificato: Ben il 23 Apr 2025
Hi,
I suggest trying C:\Progra~1\ instead of C:\Program Files\ to address the issue with the Program Files path.
Also, it’s better to check which account the Windows GitLab Runner is using when running MATLAB.
To do this:
  1. Run services.msc.
  2. Double-click the GitLab Runner service and go to the 'Log On' tab.
  3. Select 'This account' and enter the actual user account used for MATLAB.
  4. Restart the service.

Categorie

Prodotti

Release

R2023b

Richiesto:

il 28 Mar 2024

Modificato:

Ben
il 23 Apr 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by