Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multitline yaml config #1393

Open
wickedest opened this issue Oct 23, 2024 · 3 comments
Open

Multitline yaml config #1393

wickedest opened this issue Oct 23, 2024 · 3 comments
Labels
elaborate Further elaboration is needed

Comments

@wickedest
Copy link

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
Copy link
Collaborator

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
Copy link
Author

wickedest commented Oct 24, 2024

@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'

@ANGkeith
Copy link
Collaborator

hihi, sorry but i don't really understand you.

could you share again what's the exact yaml that worked in gitlab.com but didn't work in gcl ?

@firecow firecow added the elaborate Further elaboration is needed label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
elaborate Further elaboration is needed
Projects
None yet
Development

No branches or pull requests

3 participants