1

In Jenkins I'm calling a python script to do some magic actions. The pipeline is in production state for some time now and suddenly for one developer branch I'm getting

Syntax error: Unterminated quoted string

constanly this Error in Jenkins.

The causing snippet seems to be this one:

sh """
        . .venv/bin/activate
        python3 -m some_python_package.some_sub_package.script --stage update_something \
            --api PROD '$SOME_ID' '$SOME_TOKEN' --user_id ${env.CHANGE_AUTHOR_DISPLAY_NAME} --file_list ${validFilePath} 2>&1 | tee output/log.txt
"""

I already tried different escaping methods, but also this one did not help, same error message remains:

sh """
        . .venv/bin/activate
        python3 -m some_python_package.some_sub_package.script --stage update_something \
            --api PROD \'$SOME_ID\' \'$SOME_TOKEN\' --user_id ${env.CHANGE_AUTHOR_DISPLAY_NAME} --file_list ${validFilePath} 2>&1 | tee output/log.txt
"""
1
  • 1
    The actual error may precede the location where the error is finally reported. Commented Jun 7, 2022 at 15:17

2 Answers 2

3

As far as I know variables to shell should be passed with using ${XX}, e.g.

 ... ${SOME_ID} ..

but it doesn't look safe to pass token this way, I think you should pass it through environment variable

Sign up to request clarification or add additional context in comments.

2 Comments

I just changed it, but it has no impact on the pipeline run - still showing the unterminated quoted string error. Regarding safely storing API token, yes I agree!
@Scf_suedbaden ok, then it's also possible that "missing quote" appear after variables' expansion, e.g. CHANGE_AUTHOR_DISPLAY_NAME or validFilePath, try with some good default values to eliminate this case
1

Actually a very stupid case. As mentioned by @pmod one of the variables in file_list had a ' contained in a string, which messed up the shell comand... So the shell comand in the Jenkins file was correct, but I have to take care that the input values are correct as well in future

1 Comment

great that you solved it, and that my comment helped :) don't know why question -1, so I fixed it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.