I'm trying to use jenkins to run a python behave regression test pack.
I have a script block that sets the variable, I then use a shell command to prove that the variable is successful set.
However, when I run my python behave command the variable is not being passed successfully.
stage('End to end tests') {
steps {
script{
if(params.containsKey("envname")){
env_e2e = "https://url" + params.envname + ".com"
}else{
env_e2e = "https://url.com"
}
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'ui_test_user',
usernameVariable: 'UI_USERNAME', passwordVariable: 'UI_PASSWORD']]) {
sh 'sudo --preserve-env scl enable rh-python36 "cp krb5.conf /etc/krb5.conf"'
sh 'sudo --preserve-env scl enable rh-python36 "echo ${UI_PASSWORD} | kinit ${UI_USERNAME}@****.com"'
}
sh """
echo "my env ${env_e2e}"
"""
sh 'sudo --preserve-env scl enable rh-python36 "python -m pip install --force-reinstall dist/*.whl"'
sh 'sudo --preserve-env scl enable rh-python36 "behave -D ENV_E2E=${env_e2e} --tags=-skip --junit"'
}
}
post {
always {
archive "reports/*"
junit 'reports/*.xml'
}
}
}
ENV_E2E always resolves to blank
In my python behave frame work I have this environment.py file
def before_all(context):
env_var = context.config.userdata['ENV_E2E']
logging.info(env_var)
print(len(env_var))
context.pythonlib = PythonLib(service_endpoint_url=env_var)
This just returns an error at run time that env_vars len = 0 and the service_endpoint is badly format as it expects http/https
Thanks for your thoughts
Turns out you need to use triple double quoted strings, """
sh """
sudo --preserve-env scl enable rh-python36 "behave -D ENV_E2E=${env_e2e} --tags=-skip --junit"
"""
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.