maven automatically deploy artifacts on Archiva? - maven

Maybe the question is asked for more than hundred times, but I didn't find it with the search function.
Ok we've a CI Server running Jenkins and Archiva. Building our code with maven. But now our IT Department changed the proxy configuration for the CI Server. It isn't able to go online.
When I use a new artifact and build it locally, mvn downloads this and stores it in the local repo.
But when I commit the sourcecode in the SVN Jenkins fails, caused of the missing internet connection.
So is there a way to automatic deploy artifacts and maven-plugins to Archiva when I build my projects local with maven?

use mvn clean deploy that will deploy to Archiva.
You have to configure correctly distributionManagement section in your pom.
See http://archiva.apache.org/docs/1.4-M4/userguide/deploy.html

I created a Jenkins job that will execute a shell script to ask Maven to deploy our private artifact in Archiva
Prerequisites
In your .m2/settings.xml file add your server, i.e.
<server>
<id>archiva.release</id>
<username>admin</username>
<password>123456</password>
</server>
Deploy 3rd party artifacts to archiva repository shell script
#!/bin/bash
rm_host=localhost # archiva server address
rm_port=8080 # archiva port
major_version=1 #
minor_version=0 #
version_build=1 #
repository=private # your repository id in archiva
mvn deploy:deploy-file
-Dfile=myApp.jar
-DgroupId=com.company
-DartifactId=myApp
-Dversion=${major_version}.${minor_version}.${version_build}
-Dpackaging=jar
-Durl=http://${rm_host}:${rm_port}/repository/${repository}/ -DrepositoryId=archiva.release

Related

What is the difference between deploying an artifact into Artifactory with 'mvn deploy' command and with Artifactory UI?

I usually use mvn versions:use-latest-versions command to update my dependencies to the latest ones which other teams have been deployed to our free Jfrog's Artifactory server on our local address : http://192.168.100.243:8082/artifactory/X_Douran/.
My problem is when I deploy an artifact (a jar file) with Artifactory UI or with curl (using Jfrog's Rest Api), the command mvn versions:use-latest-versions doesn't work correctly and do not update my pom but when I run mvn clean deploy on my source code of my dependent project then running mvn versions:use-latest-versions on my final project it works correctly and do update my dependency in my pom.
So I want to know what is the different between deploying via Artifactory UI and deploying via mvn clean deploy ?
You always need to deploy the POM along the JAR, otherwise Maven will not work correctly with these dependencies. Furthermore, you need to make sure that the metadata files are updated. I am not sure that Artifactory does this if you deploy using curl or the UI.
Deploying your own JARs regularly through the UI is not recommended. You should build them on a build server (like Jenkins) and then automatically deploy them to Artifactory.
Changing JAR files "by hand" should be forbidden.

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.
I have a remote linux machine with Jenkins on it, and I am able to make a build of my application correctly. Now I want to deploy this build in the same linux machine, in a certain folder /deploy.
Right now I have added a Post Build Action on Jenkins to Deploy artifacts to Maven repository having the following parameters:
and right now I did not make any changes to my pom.xml or my 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. Does anyone know which are the steps to make this process work?
Thanks in advance.
Local artifact deployment is done by mvn clean install.
The install goal copies your artifact into your local maven repository (Default [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.
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)
"deploy" in Maven parlance means "upload the built artifacts and their metadata (such as pom files) to a repository manager.
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.
If that is the case then the following is how you set up the maven configuration.
Maven links credentials to servers via the id element.
Your settings.xml file would have your credentials setup something like:
<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:
<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.
The mvn deploy from Jenkins should then work correctly.

Publishing SNAPSHOT to nexus from jenkins/maven build

I'm trying to publish the result of a build jenkins/maven to a Nexus repository.
The build is a war SNAPSHOT, here is the beginning of the POM :
<http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.elis</groupIenter code hered>
<artifactId>accueil_ce</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>accueil_ce</name>
I use clean install maven goals for the build.
I've installed and configure the Nexus Repository Manager Publisher plugin for jenkins so it can publish to my nexus Repo in a post build step.
The problem is :
if I configure the repo as 'snapshot' and 'allow redeploy' in Nexus, it doesnt appear in the list of repos available in Jenkins, when configuring the after build step 'Nexus Repository Manager Publisher' of the job.
if I configure the repos as 'release' and 'allow redeploy' in Nexus, then I got the following error when running the jenkins job :
java.io.IOException:com.sonatype.nexus.api.exception.RepositoryManagerException: Unable to upload component: Bad Request The version 0.0.1-SNAPSHOT does not match the repository policy!
I don't understand, there is no way to publish SNAPSHOTs to nexus from jenkins builds with this plugin ??
You need to add distribution management to you pom to control snapshot and release repos.
See https://maven.apache.org/pom.html#Distribution_Management and How to configure maven project to deploy both snapshot and releases to Nexus?

Jenkins - Maven Configuration

I need to configure my maven project that depends on local jars. For example, in Jenkins how I can configure the third party jars that cannot be downloadable from maven central repo. In my case Microsoft JDBC driver,
mvn install:install-file -Dfile=sqljdbc4.jar -Dpackaging=jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0
Consider setting up a Maven repository manager like:
Nexus
Artifactory
Archiva
The build on Jenkins will then work the same way as a build on your development machine. This is how Maven was designed to work.

Maven - Install an artifact to the Nexus repository

I have a problem currently when i run the command mvn install, the artifact is installed in my local repository (i.e. in %HOME/.m2 folder) but not in the Nexus repository.
I know with Nexus i can add an artifact manually using the GUI but is there a way to do install the artifact as part of the mvn command?
What you're seeing is normal behavior in the standard maven lifecycle. The install phase is only supposed to install the artifact locally. You need to run deploy, which comes after install. That's when maven uploads artifacts to a remote repository. The remote repo for deployment is configured in the distribution management section of the pom.

Resources