Search code examples
bashjenkinsbackslashquoteifs

Shell quotes with IFS in Jenkins Pipeline


I'm trying to set IFS in a Bash shell within a Jenkins pipeline script. See line 34 below. The problem is I can't get the multi-level quoting correct. If I'm just typing at a bash terminal, the line would be IFS=$'\n'. But, no matter how many backslashes I use in different combinations, I can't make it work. At this point, I'm just guessing.

The $filename variable at the end of line 36 is a list of file names that have internal spaces separated by linefeed characters (\n). Hence, I want the IFS variable to be only \n.

enter image description here

Here is the same snippet in text form.

steps {
    sh """
        #!/bin/bash
        export PATH="$PATH:/root/.local/bin"
        IFS=\$\\'\\n\\'
        pip install -r requirements.txt --user
        python EC_Workload_Analysis/combine.py --webdav --zipfile ${BUILD_NUMBER} --user $SCRIPT_CREDS_USR --password $SCRIPT_CREDS_PSW $filenames
       """
      }

Solution

  • can you try with

    export IFS=$(echo -e "\n ")
    

    because you can't insert the character you need, but you can create and store it, to test this you can do

    echo "$IFS $IFS $IFS"