3

In gitlab, I made a variable SSH_PRIVATE_KEY with my private key, and try to add it on the fly with

   before_script:
     - ssh-add <(echo "$SSH_PRIVATE_KEY")

I get an error

/bin/sh: eval: line 81: syntax error: unexpected "("

How should I fix it ?

Juliatzin
  • 18,455
  • 40
  • 166
  • 325
  • Why don't you just create a file with the private key, like `ssh-add` expects? – chepner Jan 25 '19 at 16:35
  • I am following this answer https://stackoverflow.com/a/38570269/1956558 – Juliatzin Jan 25 '19 at 16:37
  • 3
    The immediate issue is that process substitution (`<(...)`) isn't supported by the POSIX shell specification, and whatever shell your system is actually using to execute the before-script doesn't either. Likely, your `/bin/sh` is something like `dash` rather than `bash`. You need to find someway to change what shell GitLab uses. – chepner Jan 25 '19 at 16:46
  • 1
    Even if `/bin/sh` *is* Bash, it'll run in POSIX mode if called as `/bin/sh` and choke on process substitution. – Benjamin W. Jan 25 '19 at 16:51
  • @chepner I am using alpine docker image. – Juliatzin Jan 25 '19 at 17:05
  • @BenjaminW. I can never remember which non-POSIX features `bash` will still support even when invoked as `sh`. – chepner Jan 25 '19 at 17:07
  • @chepner The [manual](https://www.gnu.org/software/bash/manual/bash.html#Bash-POSIX-Mode) lists just two behaviours that Bash doesn't implement even when in POSIX, but it's not explicit about what extensions are still enabled. – Benjamin W. Jan 25 '19 at 17:20

1 Answers1

0

echo "$SSH_PRIVATE_KEY" | ssh-add -

try this