CopyDisable

Monday 5 November 2012

Deploying artifacts into Artifactory repository

Continuing with my previous posts on Artifactory, in this post I will write about deploying my own jar files into the Artifactory repository. So that other projects which depends on my jar files will not have to look into any other place, they just can connect to the Artifactory repository and get the latest copy of my jar files.

I will write two ways, one using the Artifactory web GUI and second one from the command prompt.

Deploying from Artifactory Web GUI:

Deploying artifacts from Artifactory Web GUI is very simple and do not require any configuration change. So compile and package your project, get the jar file and just upload the file, that’s it.

In this example I will deploy a snapshot project in the repository. Browse and upload the jar file.

image

 

Artifactory will automatically generate the pom file after the jar file is uploaded.

image

 

Now as I am uploading a snapshot project, so I will select the default local snapshot repository (these default repositories come with Artifactory, we can create our own as per our requirement)

image

If required we can change the pom file generated by Artifactory by using the POM Editor. If everything is ok, click on Deploy Artifact button to deploy the Artifact in the repository.

image

Now we can see the artifact in the repository.

image

 

Deploying artifacts from command line:

Here we have to do some configurations.

First of all we have to find the  repository element where we are going to deploy the artifact. For that just go to Artifacts->Tree Browser and click on the repository name, (for this example we are going to deploy the artifact in the libs-snapshot-local repository) in the Distribution Management section we will get the required information. Copy the <distributionManagement> element.

image

 

Open the pom.xml file for the project, and paste the <distributionManagement> element that we copied. Edit the <id> of <distributionManagement> and set it same as the <server> element we configured in our settings.xml file (please see my previous post Configuring Artifactory to use authentication for more information).

image

image

 

Now deploy the project.

image

 

Oh no…. some error…. Access denied….hmmmm some permission related issue.

image

 

To deploy some artifact in the repository, the user we configured in the <server> section must have deploy privilege. In my previous post I showed how to connect using LDAP authentication. By default an user has only read privilege. So we must assign deploy privilege to the user.

One way is to create a group and assign deploy privilege to the group and make all the users (who will deploy into the repository) member of that group. Go to Admin –> Security –> Groups and click on New button.

 

image


Enter the name of the group and click on Create button.

image

 

Go to Admin –> Security –> Permissions and click on New button.

image

 

Enter the name of this permission settings, as I am going to deploy only in local repositories configured here, so I have selected only the Any Local Repository.

image

 

Go to Groups tab and select the Deploy privilege for the deployer group and click on Create button.

image

 

Go to Admin –> Security –> Users and select the user we want to add to the deployer group. From the Add/Remove Selected User(s) from Group list, select deployer group and click on Add to button

image

User successfully added to deployer group, now we can proceed to deploy the project again.

image

 

Deploying again, and this time deployment is successful Smile.

image

We can see the deployed project in the repository.

image

 

Instead of editing pom.xml file and adding the <distributionManagement> element, we can deploy the project into the repository directly from the command line.

mvn deploy:deploy-file -DrepositoryId=central -Durl=http://192.168.10.75:8081/artifactory/libs-snapshot-local -DgroupId=org.mkcl -DartifactId=mvntest -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=target/mvntest-1.0-SNAPSHOT.jar

image

image

1 comment:

Unknown said...

hi sir,
awesome article.but i want to deploy a .war file to artifactory server with jenkins then how shud be it done.
plz help so.
Thanks in Advance.

Post a Comment