This is piece of my yaml file about ssh for gitlab ci:
eval $(ssh-agent -s)
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
mkdir -p ~/.ssh
chmod 700 ~/.ssh
'[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
When I attempted to set SSH_PRIVATE_KEY variable to protected state, it occurs error:
Error loading key "(stdin)": invalid format
and I don't know why it's okay when I set SSH_PRIVATE_KEY variable to unprotected state
For me it also failed because the SSH_PRIVATE_KEY was marked as "Protected" but the tag I was using was not.
So either make the branch or tag you are using also protected or remove the "Protected" setting from the SSH_PRIVATE_KEY variable.
See: https://gitlab.com/help/ci/variables/README#create-a-custom-variable-in-the-ui
Protect variable (Optional): If selected, the variable will only be available in pipelines that run on protected branches or tags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With