bashshellmakefileyamlgitlab-ci

Line return not displayed with gitlab CI


I have a CI (git lab CI) which runs a shell that runs a makefile job, that calls bash scripts. The CI script is a YAML (gitlab-ci.yml) script.

YAML script:

Build:
  stage: ThisIsAnExample
  script: 
    - export OPTION1=true; make -C build/ myTarget

Makefile script:

.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS = -ec

myTarget:
    @echo "A";echo ""; print "B\n";  echo "C";  echo "";

If I run the bash script from my console, I get:

A

B

C

On the CI log I get:

A
B
C

Why aren't the line returns interpreted by gitlab CI?


Solution

  • I found a workaround.

    I made those changes :

    in my YAML gitlab-ci script:

    Build:
      stage: ThisIsAnExample
      script: 
        - export OPTION1=true; export FORCE_LR_ESCAPE_IN_CI=yes; make -C build/ myTarget
    

    in my makefile:

    .ONESHELL:
    SHELL = /bin/bash
    .SHELLFLAGS = -ec
    
    FORCE_LR_ESCAPE_IN_CI ?= no
    
    ifeq ($(FORCE_LR_ESCAPE_IN_CI),yes)
    NEW_LINE = printf '\u2000\n'
    else
    NEW_LINE = echo ''
    endif
    
    myTarget:
        @echo "A"; $(NEW_LINE); echo "B"; $(NEW_LINE);  echo "C"; $(NEW_LINE);
    

    I found that gitlab-ci skips a '\n' if it is not precessed by a character. Looks like a bug to me. Anyway, I added an invisible character ('\u2000') before the '\n' and it works!

    note: I tried with echo '\u2000' but it works only in the console, not in the ci.