简体   繁体   English

传递一个 Jenkins 变量来表现命令行参数

[英]Passing a Jenkins variable to behave command line argument

I'm trying to use jenkins to run a python behave regression test pack.我正在尝试使用 jenkins 运行 python 行为回归测试包。

I have a script block that sets the variable, I then use a shell command to prove that the variable is successful set.我有一个设置变量的脚本块,然后我使用 shell 命令来证明变量设置成功。

However, when I run my python behave command the variable is not being passed successfully.但是,当我运行 python 行为命令时,变量未成功传递。

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 ENV_E2E 始终解析为空白

In my python behave frame work I have this environment.py file在我的 python 行为框架中,我有这个 environment.py 文件

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这只是在运行时返回一个错误,即 env_vars len = 0 并且 service_endpoint 的格式错误,因为它期望 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"
"""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM