我的问题是:如何从连接到远程计算机的SSH会话中导出变量,以便在具有本地主机的shell上使用它,所有这些都在jenkins上?我的SSH脚本如下:
cd /home/$USER/link
docker-compose -f link.yml up -d #this is a script, in my case I use a docker command, the file exists and is copied in another post
echo the application is available at:
CID=$(docker ps -qf "name=webapp1" |tail -1)
app_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CID) #to get the ip address of the last container
echo $app_ip:8080
我想在主机终端上使用$app_ip
on shell,AKA但是我不知道如何继续,我的尝试是使用ssh -t [email protected] env app_ip='$(echo $app_ip)' bash -i
但显然它需要身份验证,我认为它不可能在jenkins上,你能指点我吗?朝着正确的方向?谢谢
如果你有一个名为script.sh的脚本,你可以使用$ 1,$ 2等获取输入参数或$ @来获取所有参数。
echo "Hi, the first argument is $1"
echo "Hi, all the arguments are: $@"
您可以将参数传递给它,只需将它们附加到同一行:
bash script.sh "master" "production"
结果将是:
Hi, the first argument is master
Hi, all the arguments are: master production
如果您的script.sh位于具有用户my_user的远程计算机108.107.106.105的/ devops文件夹中,则可以执行该脚本并使用以下行发送参数:
ssh -i /tmp/myKey [email protected] /devops/script.sh "master" "production"
结果将是相同的。