Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.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
Variables Jenkins在ssh命令中分配变量_Variables_Ssh_Jenkins Pipeline_Remote Server_Script - Fatal编程技术网

Variables Jenkins在ssh命令中分配变量

Variables Jenkins在ssh命令中分配变量,variables,ssh,jenkins-pipeline,remote-server,script,Variables,Ssh,Jenkins Pipeline,Remote Server,Script,我在环境部分声明了变量logfile,并在远程系统中执行ls-t-c1*.log | head-1命令后尝试分配其值 我知道我这样做是错误的。在远程系统中执行命令后,您知道如何分配变量值吗?您可以通过以下方式获取变量的返回值: # Declare variable init def logResult logResult = sshCommand remote: remote, command: "ls -t -c1 *.log | head -1" 您可以在脚本中将其用作

我在环境部分声明了变量logfile,并在远程系统中执行
ls-t-c1*.log | head-1
命令后尝试分配其值


我知道我这样做是错误的。在远程系统中执行命令后,您知道如何分配变量值吗?

您可以通过以下方式获取变量的返回值:

# Declare variable init
def logResult
logResult = sshCommand remote: remote, command: "ls -t -c1 *.log | head -1"
您可以在脚本中将其用作:

script {
 test = sh(script "echo ${logResult}")
 }

@T M Suhas我提供的解决方案对您有效吗?不,它显示了错误。它确实有效,但需要在脚本{}中编写,但是如何在sshget命令中使用变量???@T M Suhas您可以使用
${logResult}
访问它。我在answerYeah中添加了示例,当我使用echo${logResult}时,它正在打印,但当我将变量传递给sshGet时,如图所示,它并没有解析值