Cant use cat to create multi-line file in CI

In a bash script, one would normally use cat to create a file.

cat > ___check_config.js <<END_CONFIG_CHECK
let config = JSON.parse(require('fs').readFileSync('config/config.json'));
if(config.hasForceOptions !== undefined && config.hasForceOptions.enabled !== false){process.exit(255);} else {process.exit(0);}
END_CONFIG_CHECK

I would expect this to create the file (and it does, in bash)

let config = JSON.parse(require('fs').readFileSync('config/config.json'));
if(config.hasForceOptions !== undefined && config.hasForceOptions.enabled !== false){process.exit(255);} else {process.exit(0);}

BUT, when i add this script to the gitlab-ci.yml file… i get

echo $'\x1b[32;1m$ let config = JSON.parse(require(\'fs\').readFileSync(\'config/config.json\'));\x1b[0;m'
let config = JSON.parse(require('fs').readFileSync('config/config.json'));
echo $'\x1b[32;1m$ if(config.hasForceOptions !== undefined && config.hasForceOptions.enabled !== false) {process.exit(255);} else {process.exit(0);}\x1b[0;m'
if(config.hasForceOptions !== undefined && config.hasForceOptions.enabled !== false) {process.exit(255);} else {process.exit(0);}
echo $'\x1b[32;1m$ END_CONFIG_CHECK\x1b[0;m'

it contains text intended to be echoed to the onsole in the gitlab web UI.
BUG??
or, my fault?

STRANGELY… useing the same input re-direction works without error for ftp…

    #   UPLOAD TO FTP SITE.
    -   ftp -p -v -n "$RFX_FTP_URL" <<END_FTP
    -     quote USER $RFX_FTP_USER
    -     quote PASS $RFX_FTP_PASS
    -     binary
    -     prompt
    -     mdelete $GAME_NAME/*
    -     mkdir $GAME_NAME
    -     cd $GAME_NAME
    -     put $RELEASE_DIR.zip.part
    -     rename $RELEASE_DIR.zip.part $RELEASE_DIR.zip
    -     put $RELEASE_DIR.zip.sha512.part
    -     rename $RELEASE_DIR.zip.sha512.part $RELEASE_DIR.zip.sha512
    -     put $SOURCEMAP_DIR.zip.part
    -     rename $SOURCEMAP_DIR.zip.part $SOURCEMAP_DIR.zip
    -     quit
    -   END_FTP

an odd one!?

Hi @cds84

HereDocs with cat works normally, you just have to indent it correctly. This is how you do it

stages:
  - test

job1:
  stage: test
  script:
    - |
      cat > my_file << EOF
      This is text
      I want in my file.
      And nothing else will
      be
      here
      EOF
    - cat my_file

and this is how it looks

...
$ cat > my_file << EOF # collapsed multi-line command
$ cat my_file
This is text
I want in my file.
And nothing else will
be
here
...
1 Like