Jenkins执行shell脚本时要设置权限

目前出现了一个问题,当我独自用shell脚本执行启动springBoot时  就可以注册到eureka上

如果用jenkins执行shell脚本时 就会出现注册不上去的情况

2020-11-18 13:47:54.808  INFO 29482 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_XIANNANSHAN-USER/172.17.165.145:xiannanshan-user:8060: registering service...
2020-11-18 13:47:54.994  INFO 29482 --- [extShutdownHook] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
2020-11-18 13:47:55.050  INFO 29482 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_XIANNANSHAN-USER/172.17.165.145:xiannanshan-user:8060 - registration status: 204
2020-11-18 13:47:55.053  INFO 29482 --- [extShutdownHook] com.netflix.discovery.DiscoveryClient    : Unregistering ...
2020-11-18 13:47:55.246  INFO 29482 --- [extShutdownHook] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_XIANNANSHAN-USER/172.17.165.145:xiannanshan-user:8060 - deregister  status: 200
2020-11-18 13:47:55.273  INFO 29482 --- [extShutdownHook] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClient

聪明的我领悟到有可能是因为shell脚本没有权限执行文件  

在Jenkins执行shell脚本时:

于是在shell脚本前面加上sudo 提权执行

echo "开始执行maven打包"
mvn clean install package -Dmaven.test.skip=true
echo "maven打包完成"
echo "开始复制jar包"
pwd
cd /root/.jenkins/workspace/xiannanshan-parents/
sh xiannanshan-publish.sh backup user prod
sodo sh xiannanshan-publish.sh backup cloud-parent prod
find /root/.jenkins/workspace/xiannanshan-parents -name '*.jar' -exec cp {} /usr/local/xiannanshan/xiannanshan-parents/lib/ \;
sodo sh xiannanshan-publish.sh restart cloud-parent prod
sudo sh xiannanshan-publish.sh restart user prod

  

 

上一篇:Spring Cloud Alibaba 03:Ribbon负载均衡


下一篇:云安全常见的AWS错误配置