简体   繁体   English

Jenkins-将工件部署到Maven存储库

[英]Jenkins - deploy artifacts to Maven repository


I have a basic Springboot Maven project and I want to be able to deploy it and make API call as it works in local. 我有一个基本的Springboot Maven项目,我希望能够部署它并在本地工作时进行API调用。
I have a remote linux machine with Jenkins on it, and I am able to make a build of my application correctly. 我有一台装有Jenkins的远程linux机器,并且能够正确构建我的应用程序。 Now I want to deploy this build in the same linux machine, in a certain folder /deploy . 现在,我想将此构建版本部署在同一Linux机器的某个特定文件夹/deploy
Right now I have added a Post Build Action on Jenkins to Deploy artifacts to Maven repository having the following parameters: 现在,我在Jenkins上添加了一个Post Build Action ,以将工件部署到具有以下参数的Maven存储库 在此处输入图片说明 and right now I did not make any changes to my pom.xml or my maven settings.xml . 现在,我没有对pom.xml或maven settings.xml进行任何更改。 The error that I get is the following: 我得到的错误如下:

[INFO] Deployment in http://localhost:8080/deploy (id=test2,uniqueVersion=true)
Deploying the main artifact reag.login-0.0.1-SNAPSHOT.jar
Downloading: http://localhost:8080/deploy/reag/login/reag.login/0.0.1-SNAPSHOT/maven-metadata.xml
ERROR: Failed to retrieve remote metadata reag.login:reag.login:0.0.1-SNAPSHOT/maven-metadata.xml: Could not transfer metadata reag.login:reag.login:0.0.1-SNAPSHOT/maven-metadata.xml from/to deploymentRepo (http://localhost:8080/deploy): Access denied to: http://localhost:8080/deploy/reag/login/reag.login/0.0.1-SNAPSHOT/maven-metadata.xml , ReasonPhrase:Forbidden.
org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to retrieve remote metadata reag.login:reag.login:0.0.1-SNAPSHOT/maven-metadata.xml: Could not transfer metadata reag.login:reag.login:0.0.1-SNAPSHOT/maven-metadata.xml from/to deploymentRepo (http://localhost:8080/deploy): Access denied to: http://localhost:8080/deploy/reag/login/reag.login/0.0.1-SNAPSHOT/maven-metadata.xml , ReasonPhrase:Forbidden.

The machine where I'm working is protected by username and password, I tried to put them in the settings.xml file but nothing changes. 我正在使用的计算机受用户名和密码保护,我尝试将它们放在settings.xml文件中,但没有任何变化。 Does anyone know which are the steps to make this process work? 有谁知道使该过程正常进行的步骤?
Thanks in advance. 提前致谢。

Local artifact deployment is done by mvn clean install . 本地工件部署是通过mvn clean install完成的。 The install goal copies your artifact into your local maven repository (Default [USER_HOME]/.m2/repository). install目标会将您的工件复制到本地Maven存储库(默认为[USER_HOME] /。m2 / repository)。

If you want to deploy your artifact to another service, like a Nexus Maven Repository , then you need to deploy and also provide the credentials for that machine in your settings.xml , or even better setup a private/public key authentication for the machines. 如果要将工件部署到Nexus Maven存储库等其他服务,则需要在settings.xml部署并提供该机器的凭据,甚至更好地为机器设置私钥/公钥身份验证。

I think Jenkins is trying to do the remote deploy, which is only working if you run a Maven Repository on your machine (like the Nexus) 我认为Jenkins正在尝试进行远程部署,这仅在您在计算机(例如Nexus)上运行Maven存储库时才有效

"deploy" in Maven parlance means "upload the built artifacts and their metadata (such as pom files) to a repository manager. 在Maven中,“部署”的意思是“将构建的工件及其元数据(例如pom文件)上传到存储库管理器。

It does not mean "copy the artifact to any location that you want". 并不意味着“神器复制到任何你想要的位置。”

Therefore as @funfried mentioned, you need to actually have a repository manager running. 因此,正如@funfried所提到的,您实际上需要运行一个存储库管理器。

If that is the case then the following is how you set up the maven configuration. 在这种情况下,以下是设置Maven配置的方法。

Maven links credentials to servers via the id element. Maven通过id元素将凭证链接到服务器。

Your settings.xml file would have your credentials setup something like: 您的settings.xml文件将设置您的凭据,如下所示:

<servers>
    <server>
        <id>newhope-nexus</id>
        <username>steve</username>
        <password>{1T7Jmp/PBoQH4cvFjZDTaDe/F/Z+D9rJ925rf+3H1LY=}</password>
    </server>
</servers>

And then your project model (project pom or parent pom) should define it's distributionManagement : 然后,您的项目模型(项目pom或父pom)应该定义它的distributionManagement

<distributionManagement>
    <repository>
        <id>newhope-nexus</id>
        <url>http://newhope:8081/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>newhope-nexus</id>
        <url>http://newhope:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

Note that the ids all match. 请注意,所有ID均匹配。

The mvn deploy from Jenkins should then work correctly. 然后,从詹金斯(Jenkins) mvn deploymvn deploy应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM