Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Jenkins文件中使用docker image内部环境变量?_Docker_Jenkins_Environment Variables_Jenkins Pipeline - Fatal编程技术网

如何在Jenkins文件中使用docker image内部环境变量?

如何在Jenkins文件中使用docker image内部环境变量?,docker,jenkins,environment-variables,jenkins-pipeline,Docker,Jenkins,Environment Variables,Jenkins Pipeline,我目前面临的问题是,Jenkins试图从外部访问/替换sh脚本中的env变量,而属性是在容器内部定义的: stage('Run phpunit') { agent { docker { image 'php:7.2-alpine' } } steps { sh """ apk add --no-cache ${PHPIZE_DEPS} pecl ins

我目前面临的问题是,Jenkins试图从外部访问/替换
sh
脚本中的env变量,而属性是在容器内部定义的:

    stage('Run phpunit') {
      agent {
        docker { image 'php:7.2-alpine' }
      }
      steps {
        sh """
          apk add --no-cache ${PHPIZE_DEPS}
          pecl install xdebug
          docker-php-ext-enable xdebug
          php vendor/bin/phpunit --colors=never --log-junit build/junit.xml --coverage-clover build/clover.xml
        """
      }
    }
Jenkins未能完成此步骤,并显示以下消息:

groovy.lang.MissingPropertyException: No such property: PHPIZE_DEPS for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:242)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)

问题在于Groovy使用了与Bash所解释的相同的
“${VAR}”
语法。只需使用
\
$
转义即可:

sh """ apk add --no-cache \${PHPIZE_DEPS} ...