>我正在使用Maven 3
>我正在使用Eclipse Keppler
>我正在使用jenkins
>远程服务器正在运行Ubuntu Server 11.04
> Jenkins正在ubuntu服务器上运行
>我的本地计算机正在运行windows XP
我的第一次尝试是用我的机器.我在Eclipse中运行Maven来进行部署,一切正常.我将以下内容添加到我的项目pom中
<build> ... <extensions> <extension> <groupID>org.apache.maven.wagon</groupID> <artifactID>wagon-ssh-external</artifactID> <version>1.0-beta-6</version> </extension> </extensions> ... </build>...<distributionManagement> <repository> <ID>my server ID</ID> <name>my repository name</name> <url>scpexe://my server//path/to/my/repository</url> </repository> </distributionManagement>
在我的settings.xml中,我添加了
<servers> <server> <ID>my server ID</ID> <username>server username</username> <password>server password</password> <configuration> <sshExecutable>plink</sshExecutable> <scpExecutable>pscp</scpExecutable> </configuration> </server> </servers>
所以在我的本地机器上它可以工作,但我需要使用Jenkins来完成这项工作.我修改了Jenkins settings.xml,因为它在linux上运行,所以不需要sshExecutable. Jenkins settings.xml看起来像
<servers> <server> <ID>my server ID</ID> <username>server username</username> <password>server password</password> </server> </servers>
然后我修改了pom.xml来执行scp而不是scpexe
<distributionManagement> <repository> <ID>my server ID</ID> <name>my repository name</name> <url>scp://my server//path/to/my/repository</url> </repository> </distributionManagement>
但根据这个页面https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes maven 3不支持scp.我以任何方式运行它,我从Jenkins日志中收到以下错误消息
mavenExecutionResult exceptions not emptymessage : Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project myproject: Failed to deploy artifacts/Metadata: No connector available to access repository my_repository (scp://my server//path/to/my/repository) of type default using the available factorIEs WagonRepositoryConnectorFactorycause : Failed to deploy artifacts/Metadata: No connector available to access repository my_repository (scp://my server//path/to/my/repository) of type default using the available factorIEs WagonRepositoryConnectorFactoryStack trace :
如果我使用scpexe而不是scp,我会收到另一条错误消息
mavenExecutionResult exceptions not emptymessage : Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project pruebanueva: Failed to deploy artifacts: Could not transfer artifact {$groupID}:{$artifactID}:{$package}:{$version} from/to my_repository (scpexe://my server//path/to/my/repository): Error executing command for transfercause : Failed to deploy artifacts: Could not transfer artifact {$groupID}:{$artifactID}:{$package}:{$version} from/to my_repository (scpexe://my server//path/to/my/repository): Error executing command for transferStack trace :
我可以进行部署的唯一方法是分两步完成
>配置Jenkins以实现安装目标
>从命令行运行以下命令
mvn deploy:deploy-file -DgroupID=$groupID -DartifactID=$artifactID
-Dversion=$version -Dpackaging=jar -Dfile=path/to/file.jar -Durl=scp://my server//path/to/my/repository -DrepositoryID=my repository ID
我尝试了很多东西,包括将该命令写入Jenkins目标,但每次我在Jenkins中使用scp命令时,构建都会失败.
任何想法如何解决这个问题将不胜感激.
解决方法 我有兴趣看看是否有任何真正的Maven解决方案.我一直使用Maven Antrun插件修复此问题,如下所示:<profile> <ID>deploy</ID> <activation> <property> <name>deployment.server</name> </property> </activation> <build> <plugins> <plugin> <groupID>org.apache.maven.plugins</groupID> <artifactID>maven-antrun-plugin</artifactID> <version>1.7</version> <executions> <execution> <phase>deploy</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <echo>deploying to server: ${deployment.server}</echo> <taskdef classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp" name="scp" /> <scp file="${project.build.directory}/${project.artifactID}.war" password="${deployment.password}" todir="${deployment.username}@${deployment.server}:" trust="true" verbose="true" /> <!-- <sshexec command="echo unity | sudo -S cp ${project.build.finalname}.jar $( if [ -e /station ]; then echo /station/lib; else echo /opt/pkg-station*/webapps/station*/WEB-INF/lib; fi )" host="${targetStation}" password="unity" trust="true" username="wps"></sshexec> --> </target> </configuration> </execution> </executions> <dependencIEs> <dependency> <groupID>com.jcraft</groupID> <artifactID>Jsch</artifactID> <version>0.1.25</version> </dependency> <dependency> <groupID>org.apache.ant</groupID> <artifactID>ant-Jsch</artifactID> <version>1.7.1</version> </dependency> </dependencIEs> </plugin> <plugin> <groupID>org.apache.maven.plugins</groupID> <artifactID>maven-deploy-plugin</artifactID> <version>2.7</version> <configuration> <skip>true</skip> </configuration> </plugin> </plugins> </build></profile>
关于此的一些注意事项:我通过运行到部署阶段并提供deployment.server设置来激活此配置文件.为方便起见,我将相应的设置添加到我的settings.xml中,这样我就不必每次都在命令行上提供这些设置:
<profile> <ID>alwaysActiveProfile</ID> <propertIEs> <deployment.server>10.10.10.10</deployment.server> <deployment.username>username<deployment.username> <deployment.password>password</deployment.password> </propertIEs></profile>
我跳过实际的部署目标,因为它将在我运行到部署阶段时执行,这是我不想要的.
总结以上是内存溢出为你收集整理的linux – 如何使用scp将maven3工件部署到远程服务器全部内容,希望文章能够帮你解决linux – 如何使用scp将maven3工件部署到远程服务器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)