问题描述
不幸的是,我正在尝试获取在管道中声明的环境变量,但我没有在 ssh 代理 shell 命令中获取管道环境变量。
不幸的是,我正在尝试获取在管道中声明的环境变量,但我没有在 ssh 代理 shell 命令中获取管道环境变量。
请在下面找到代码:
#!groovy
library 'reference-pipeline'
pipeline{
agent {
label 'Weblogic||Tomcat'
}
environment{
HostName='test.prod.com'
sshserver="ssh -o StrictHostKeyChecking=no user@${HostName}"
SERVER_ADDRESS='192.25.58.201'
CONfig='PRODUCTION'
}
stages
{
stage("Check TLA version")
{
steps{
script{
sshagent(credentials : ['SSH_Credentials']) {
sh """
set -e
$sshserver << "EOF"
echo "Configuration:$CONfig" // output "Configuration: " should be "Configuration:production"
echo " Server:$SERVER_ADDRESS" // output "Server: " should be "Server: 192.25.58.201"
echo " Server Host : $hostname" // output "server host: testgood"
echo "started"
'`git describe`'
echo "ended"
cd /var/lib/ubuntu/test-srv/current
server_version="`git describe`"
echo "Current server version: $server_version"
if [[ $server_version != *'1.0.0_Release'* ]]; then
echo "Error: The underlying server version is not 1.0.0_Release Release. Exiting ..."
exit 1
fi
EOF
"""
}
}
}
}
}
post {
always {
cleanWs()
}
}
}
解决方法
代替:
echo "Configuration:$CONFIG"
试试:
echo "Configuration: ${env.CONFIG}"