firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.32k stars 132 forks source link

Multitline yaml config #1393

Open wickedest opened 1 day ago

wickedest commented 1 day ago

Minimal .gitlab-ci.yml illustrating the issue

---
job:
  script:
    - echo $VAL1
    - echo $VAL2
    - echo $VAL3
    - echo $VAL4
    - echo $VAL5
# .gitlab-ci-local-variables.yml

VAL1: 'Host gitlab.com
  HostName gitlab.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_autobot_ed25519'
VAL2: |
  Host gitlab.com
    HostName gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_autobot_ed25519
VAL3: Host gitlab.com
  HostName gitlab.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_autobot_ed25519
VAL4: "
  Host gitlab.com
    HostName gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_autobot_ed25519
  "
VAL5: >2
  Host gitlab.com
    HostName gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_autobot_ed25519

Expected behavior It should echo multiline values preserving the \n character.

Actual behavior

build             $ echo $VAL1
build             > Host gitlab.com HostName gitlab.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_autobot_ed25519
build             $ echo $VAL2
build             > Host gitlab.com HostName gitlab.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_autobot_ed25519
build             $ echo $VAL3
build             > Host gitlab.com HostName gitlab.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_autobot_ed25519
build             $ echo $VAL4
build             > Host gitlab.com HostName gitlab.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_autobot_ed25519
build             $ echo $VAL5
build             > Host gitlab.com HostName gitlab.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_autobot_ed25519

Host information Ubuntu gitlab-ci-local 4.1.33

Containerd binary No

Additional context I am trying to replicate the gitlab environment variables locally and I am struggling. In gitlab, my script creates .ssh/config by echoing the value of the file, which is stored in gitlab variables. The script basically just does echo:

echo $VAL1 > ~/.ssh/config

However, no matter what multiline format I use, the line endings are striped and the multilines are converted to a single string. Either I am doing this wrong, or this is a bug.

PS. gitlab-ci-local is awesome - tyvm! I'm eager to get it working.

ANGkeith commented 16 hours ago

hey, i don't think this is a bug on our side but rather quirks with shell

try surrounding your variables with double quotes

image

wickedest commented 3 hours ago

@ANGkeith, thanks for your quick reply. I tried what you suggest and got it to work, but it only works with .env. The yaml config behaves differently and only ever produces one line.

This is exactly what I am using:

image

Your explanation is clear. I don't know what wizardry gitlab is using, but unfortunately it requires that I change my CI to work-around this difference in behaviour, which is unfortunate.

Incidentally, I came across another separate, but related issue. I'll raise a separate ticket.

I can confirm the quotes trick works with file .env config as well:

VAL1='~/.ssh/known_hosts'