How to use Jenkins Environment variables in python script
That's what you need if I understand you correctly:
QUALIFIER="$(echo $BUILD_ID | sed "s/[-_]//g" | cut -c1-12)"
export QUALIFIER
python my_script.py
And in your Python script:
import os
qualifier = os.environ['QUALIFIER']
or without the shell part:
import os
import re
qualifier = re.sub(r'[-_]+', '', os.environ['BUILD_ID'])[0:12]
import os
os.environ.get("variable_name")