詹金斯2.2024.2
Kubernetes插件1.22.0env.JAVA_HOME
变量被设置为不同于sh 'printenv'
显示的值。我以为env
是环境的反映。我也找不到在哪里设置env.JAVA_HOME
。它不反映Global JDK配置中的值。我还为Jenkins Master根目录添加了openjdk,只找到了正确的值。
bash-4.4# grep openjdk *
config.xml: <home>/usr/local/openjdk-8/jre</home>
这是演示行为的管道。
pipeline {
agent {
kubernetes { label 'java8-mvn3' }
}
stages {
stage('test') {
steps {
container ('java8-mvn3') {
echo env.JAVA_HOME
echo "++++++++++++++++++++++++++"
sh 'printenv | grep JAVA_HOME'
}
}
}
}
}
**输出**
[Pipeline] echo
/usr/lib/jvm/java-1.8-openjdk
[Pipeline] echo
++++++++++++++++++++++++++
[Pipeline] sh
+ printenv
+ grep JAVA_HOME
JAVA_HOME=/usr/local/openjdk-8
最佳答案
按照手册页:http://man7.org/linux/man-pages/man1/printenv.1.html
NOTE: your shell may have its own version of printenv, which usually
supersedes the version described here. Please refer to your shell's
documentation for details about the options it supports.
因此,许多人都需要使用特定的外壳,例如
sh '''#!/bin/bash -c ...
或者作为另一种选择,导出全局/阶段定义环境级别所需的一个