Jenkins使用Publish over SSH插件,pipeline执行kubectl apply命令报错error: Unexpected args:xxx.yaml

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脚本,执行结果如下:

 运行成功。

猜你喜欢

转载自blog.csdn.net/qq_46274911/article/details/130359498
今日推荐