Issue
Below is the snippet from my python script which runs fine from pycharm but if run from Jenkins job's Execute shell the job is failing with error saying SyntaxError: invalid syntax at CURRENT_MONTH: Final = "cur_mon"
from typing import Final
CURRENT_MONTH: Final = "cur_mon"
LAST_MONTH: Final = "last_mon"
data_timeline = [CURRENT_MONTH, LAST_MONTH]
Command used in Jekins job is python my_file.py
and pyhton3 my_file.py
. In both cases it is failing with same error.
Please advise on what could be going wrong here.
Solution
Your Jenkins is running Python < 3.6
. The variable annotation syntax came in Python 3.6
:
https://www.python.org/dev/peps/pep-0526/
Also, Final
got introduced in Python 3.8
(but missing it would of course raise an ImportError
instead of a SyntaxError
):
https://www.python.org/dev/peps/pep-0591/
Answered By - ruohola