如何通过 scp 插件从 Jenkins 访问远程主机上的 /var/lib/tomcat6/webapps

Rus*_*man 0 tomcat jenkins jenkins-plugins

我在 Jenkins 上使用scp插件将我的项目的 WAR 传送到远程主机。

手动,我会将该 WAR 复制到该主机上的我的用户,然后自己去那里,获取 root (sudo) 并将 WAR 复制到/var/lib/tomcat6/webapps 中,Tomcat 会立即部署它。

但是,由于用户tomcat6没有可发现的密码,因此我找不到将tomcat6用作scp用户的方法,因此我无法告诉 Jenkins 如何在没有键盘交互的情况下执行此操作——使用 Jenkins 进行连续渲染部署没用。

我在 Precise 服务器上运行 Jenkins,要部署 WAR 的远程服务器也在运行 Precise。

感谢任何阅读这个问题的人,并非常感谢任何可以让我直接了解实现这一目标的聪明方法的人。

这是詹金斯的相关输出(失败):

BUILD SUCCESSFUL
Total time: 29 seconds
[SCP] Connecting to app-1.site
[SCP] uploading file: '/var/lib/tomcat6/webapps/myapp.war'
ERROR: Failed to upload files
3: Permission denied
    at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2289)
    at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:485)
    at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:439)
    at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:406)
    at be.certipost.hudson.plugin.SCPSite.upload(SCPSite.java:239)
    at be.certipost.hudson.plugin.SCPRepositoryPublisher.perform(SCPRepositoryPublisher.java:211)
    at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:804)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:776)
    at hudson.model.Build$BuildExecution.post2(Build.java:183)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:726)
    at hudson.model.Run.execute(Run.java:1600)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:241)
Build step 'Publish artifacts to SCP Repository' changed build result to UNSTABLE
Finished: UNSTABLE
Run Code Online (Sandbox Code Playgroud)

有两种解决方案可以尝试,但我认为哪个都不好。在我看来,真正的方法是能够以真正的用户身份使用tomcat6。为此,它必须有一个可控的密码。

尝试的解决方案

1)给tomcat6一个密码。不知道 a) 这是否可以完成,b) 即使我们尝试它也会工作或 c) 这是否会简单地破坏 Tomcat 安装,而我现在不想这样做。需要研究。

2) 在/var/lib/tomcat6/webapps上设置权限,以便我的用户或我专门为该作业创建的其他用户可以复制到该路径,并且 Tomcat 愿意部署在那里复制的任何内容。可能需要在构建期间从 ant 修改对 WAR 文件的权限。