jenkins tomcat ssh权限被拒绝
尝试使用管道中的Jenkins ssh代理插件将war文件复制到tomcat,两者都运行在Ec2上的Ubuntu18.04上 使用标准示例代码和基于密钥的身份验证。Tomcat正在运行jenkins tomcat ssh权限被拒绝,tomcat,jenkins,jenkins-pipeline,ubuntu-18.04,ssh-agent,Tomcat,Jenkins,Jenkins Pipeline,Ubuntu 18.04,Ssh Agent,尝试使用管道中的Jenkins ssh代理插件将war文件复制到tomcat,两者都运行在Ec2上的Ubuntu18.04上 使用标准示例代码和基于密钥的身份验证。Tomcat正在运行 stage('Deploy to Tomcat'){ sshagent(['Tomcat-cred']) { sh 'scp -o StrictHostKeyChecking=no target/*.war ubuntu@xxxx:/opt/tomcat/latest/webap
stage('Deploy to Tomcat'){
sshagent(['Tomcat-cred']) {
sh 'scp -o StrictHostKeyChecking=no target/*.war ubuntu@xxxx:/opt/tomcat/latest/webapps/'
}
}
获取错误:scp:/opt/tomcat/latest/webapps//myweb-0.0.7-SNAPSHOT.war:权限被拒绝
已将tomcat用户设置为具有“最新”符号链接权限
以下是我的文件权限:
我现在尝试了一些更改:
scp:/opt/tomcat/latest/webapps/:没有这样的文件或目录
scp:/opt/tomcat/apache-tomcat-9.0.26/webapps/:没有这样的文件或目录
目录当然存在:
ubuntu@ip-xxxxx:/opt/tomcat/apache-tomcat-9.0.26$ ls
webapps
我想出了一些解决办法 1.将文件发送到另一个目录,然后再次复制到目标目录
stage('Deploy to Tomcat'){
sshagent(['Tomcat-cred']) {
sh """
scp -o StrictHostKeyChecking=no target/*.war ubuntu@xxxx:/home/ubuntu
ssh -o StrictHostKeyChecking=no ubuntu@xxxx 'cp -r /home/ubuntu/*.war /opt/tomcat/latest/webapps/'
"""
}
}
2.不只是使用sshagent插件
stage('Deploy to Tomcat'){
script {
// you may need to set ssh keys on target server
sh 'scp -o StrictHostKeyChecking=no target/*.war ubuntu@xxxx:/opt/tomcat/latest/webapps/'
}
}
我希望你能解决这个问题。这个问题原来是个错误喜剧。对不起 问题在于AWS上的IP地址不断变化——在您停止并重新启动正常行为之后。我一直在搞砸Jenkins配置和Jenkins文件中的IP——Tomcat服务器和Jenkins服务器IP,不知何故,其中一个很难跟上。但我一直在检查终端-在终端上,您当然需要有正确的IP,这使得调试变得很困难
哦,有时候简单的事情也会搞砸在Tomcat_服务器中更改Web应用的所有权可以避免这个错误
chown -R ec2-user:ec2-user /opt/apache-tomcat-9.0.29/webapps
tomcat用户真的有写东西的先决条件吗ubuntu@xxxx:/opt/tomcat/latest/webapps/?直接从命令行试试怎么样。也许这不是sshAgent的问题。我在与Jenkins进行ssh时使用“ubuntu”用户,但该用户也应该有权限。在上面的帖子中添加了更多细节。现在的错误是不同的-没有这样的文件我试图在谷歌搜索与“scp没有这样的文件或目录,但文件存在”,有几种解决方案,但我不确定哪一个会解决你的问题。。也许你可以试试这些解决办法。@tonarimochi-ThanksIt很高兴知道问题已经解决了!我很高兴你发现了原因,并把它分享给这里:D
chown -R ec2-user:ec2-user /opt/apache-tomcat-9.0.29/webapps