How do I resolve Git clone URL rejection errors due to line endings?

Last updated: September 15, 2025

Context

When running Git clone commands in shell scripts within Spacelift, you may encounter a "URL rejected: Malformed input to a URL function" error. This typically occurs when the script file contains Windows-style line endings (CRLF) instead of Unix-style line endings (LF), which can cause issues with how the Git API key is processed.

Answer

To resolve the Git clone URL rejection error, you need to ensure your shell script uses the correct line endings. There are two ways to fix this:

Option 1: Convert the file using dos2unix

  1. Add the following command as a task before running your script:

    dos2unix /mnt/workspace/test.sh && sh /mnt/workspace/test.sh

Option 2: Use sed to remove carriage returns

  1. Add the following command as a task:

    sed -i $'s/\r$//' /mnt/workspace/test.sh && sh /mnt/workspace/test.sh

For a permanent solution, you can add either of these commands as a before_init hook in your Spacelift configuration to automatically handle line ending conversion before each run.

Note: This issue commonly occurs when scripts are created or edited on Windows systems and then used in Linux-based environments. To prevent this issue, consider configuring your Git client to automatically handle line endings or use a text editor that supports Unix-style line endings.