Gitlab CI with MATLAB

I have gitlab CI checking some scripts and I used the following lines .gitlab-ci.yml to show the result of the MATLAB assembly:

before_script:

test1:
 script:
   - matlab -nosplash -nodesktop -minimize -wait -logfile matlab-output.txt -r Model
   - type matlab-output.txt

This works fine when the build is successful, but not when it fails, because the second command does not start. I am checking out gitlab-ci-runner and it does not have the "after_script" option. How did you handle this?

Note: this is Windows.

+4
source share
5 answers

Sorry for the long delay and thank you all for your help. Now I have a working system using Suever code. I modified it to fit the structure of the MATLAB module.

So finally my .gitlab-ci.yml:

before_script:

Model-01:
  script:
    - cd developers\testModel\01
    - Gitlab_CI_Hook.cmd

Model-02:
  script:
    - cd developers\testModel\02
    - Gitlab_CI_Hook.cmd

Gitlab_CI_Hook.cmd:

matlab -nosplash -nodesktop -minimize -wait -logfile matlab-output.txt -r Git_MATLAB_interface
type matlab-output.txt

set content=
for /f "delims=" %%i in (ExitCode.txt) do set content=%content% %%i

exit %content%

Git_MATLAB_interface.m

% assume it always fails
exit_code = 1;

% MATLAB runs the test
result = runtests(pwd)

% check the result
if result.Passed ~= 0 && result.Failed == 0 && result.Incomplete == 0
    exit_code = 0;
end

% write the ExitCode
fid = fopen('ExitCode.txt','w');
fprintf(fid,'%d',exit_code);
fclose(fid);

% Ensure that we ALWAYS call exit that is always a success so that CI doesn't stop
exit
0

, . , GITLAB type, , MATLAB , script .

, :

# This one will fail and notice that it never ends
matlab -nodesktop -nosplash -minimize -wait -logfile log.txt -r 'disp(a); exit;'

, MATLAB exit.

, exit .

# This one will pass
matlab -nodesktop -nosplash -minimize -wait -logfile log.txt -r 'disp(1); exit;'

, , . -, , try/catch, / .

runtests.m

% runtests.m
exit_code = 0;

try
    Model
catch ME
    disp(getReport(ME))
    exit_code = 1;
end

% Ensure that we ALWAYS call exit
exit(exit_code);

bash script, MATLAB , MATLAB

# runtests.sh
LOGFILE=log.txt

matlab -nodesktop -nosplash -minimize -wait -logfile "$LOGFILE" -r 'runtests';
CODE=$?

cat "$LOGFILE"

exit $CODE

, , GITLAB CI .

.gitlab-ci.yml

test1:
  script:
  - "runtests.sh"
+4

, , matlab ... , type matlab-output.txt .

, Model script/, try/catch.

.

matlab -nosplash -nodesktop -minimize -wait -logfile matlab-output.txt -r "try; Model; end;"

exit , Matlab, :

matlab -nosplash -nodesktop -minimize -wait -logfile matlab-output.txt -r "try; Model; catch; quit force; end;"

try/catch Model.m

+2

, , "type matlab-output.txt" , . , , , , , -, , -, , .

, , , :

stages:
 - build
 - postbuild

before_script:

test1:
 stage: build
 script:
   - matlab -nosplash -nodesktop -minimize -wait -logfile matlab-output.txt -r Model
typematlab:
  stage: postbuild
  script:
   - type matlab-output.txt
  when: always

, .

+2

CON ? .

matlab -nosplash -nodesktop -minimize -wait -logfile CON -r Model
+1

Source: https://habr.com/ru/post/1623191/


All Articles