【问题标题】:How to set http proxy in Jenkins如何在 Jenkins 中设置 http 代理
【发布时间】:2022-01-01 07:57:15
【问题描述】:

我使用这个Link 在 Jenkins 中配置 http 代理,但是在使用 printenv 之后只设置了这些变量。

HTTP_PROXY=http://127.0.0.1:3128
https_proxy=http://127.0.0.1:3128

我预计 http_proxyHTTPS_PROXY 也会设置。

我在构建阶段添加了以下步骤来设置这些环境变量,但 http_proxyHTTPS_PROXY 没有设置。

   stage('build') {
        
        steps {
            echo "************ Before exporting ***************************"
            sh 'printenv | sort'
            sh "export http_proxy='http://127.0.0.1:3128'"
            sh "export https_proxy='http://127.0.0.1:3128'"
            sh "export HTTP_PROXY='http://127.0.0.1:3128'"
            sh "export HTTPS_PROXY='http://127.0.0.1:3128'"
            echo "************ After exporting ***************************"
            sh 'printenv | sort'
            echo "**************************************************"
            sh './myScript'
        }
    }

您能否帮我弄清楚问题出在哪里并让myScript 运行,现在它只是失败了,因为这些变量设置不正确?

【问题讨论】:

    标签: jenkins environment-variables


    【解决方案1】:

    如果这个脚本只需要代理,你可以使用以下:

    withEnv(['HTTP_PROXY=http://${YOUR_PROXY}','HTTPS_PROXY=http://${YOUR_PROXY}']) {
        sh './myScript'    
    }
    

    【讨论】:

    • 我也试过了,但是打印HTTPS_PROXYHTTP_PROXY 总是空的
    猜你喜欢
    • 1970-01-01
    • 2012-07-28
    • 2011-10-04
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多