jenkins配置Publish over ssh插件,将yaml配置文件通过ssh发送到K8s集群某个文件路径下,ssh运行命令
sh "ssh [email protected] kubectl apply -f /xxx/xxx/xxx/xxx.yaml"
报错:
但是ssh执行kubectl apply -h命令能够成功。命令没有问题,我是传送到k8s集群中的yaml文件权限出现问题:
上传的文件最开始root用户只有read和write权限,没有执行权限,如上图deploy.yml文件。
解决办法:
在执行sshPublisher之后,运行apply -f xxx.yaml文件之前,执行命令:
sh "ssh [email protected] chmod +x /xxx/xxx/xxx/xxx.yaml"
以便添上用户的执行权限。
再次运行pipeline脚本,执行结果如下:
运行成功。