So far I have covered how to setup Git, Eclipse, Jenkins, Code Stream, and a little Artifactory. We have Eclipse checking code into Git and Jenkins pulling the code and simply building it into a tar.gz file. We also have Code Stream setup to use Artifactory and established the means by which Code Stream will talk to Jenkins, but we are still missing some pieces we need before we can really dig into how to use Code Stream. I know this may seem a bit confusing, but I promise it will all make sense very soon.
We now need to connect Jenkins to Artifactory. Why you ask? We are going to connect Jenkins to Artifactory so it can publish the tar,gz file as an artifact in the Artifactory repository. We need to do this so we can later have code stream pull it from Artifactory. the cool part is not only can we utilize this artifact with Code Stream, but it can be used with out solutions as well like vRealize Application Services if we wanted. Ok let’s not get to far ahead. In this article we are simply going to connect Jenkins to Artifactory and modify our build to publish the tar.gz file as an artifact to a repository.
Installing the Jenkins Artifactory plugin
1. Login to your Jenkins server and navigate to Manage Jenkins –> Manage Plugins and go to the Available tab. Once there search for the Artifactory Plugin and select it to be installed, then click Install without restart. If after it install’s it states it needs a reboot check the reboot box to reboot the Jenkins server. Once complete you should see the Artifactory Plugin under the installed tab.
2. Next we need to import the Artifactory SSL certificate on to the Jenkins server. First we need to export the Artifactory SSL certificate. We do that by using either firefox or I.E. to export it. Make sure you export the certificate as X.509 DER.
3. Once you have the certificated exported you need to get it on to the Jenkins server so we can import it. After you have the certificate on the Jenkins server from the console as root execute the following command:
keytool -import -v -trustcacerts -alias artifactory_hostname -file artifactory_certificate.cer -keystore /usr/lib/jvm/jre/lib/security/cacerts -keypass changit -storepass changeit
*Note – If you have changed the deault keypass and storepass please replace changeit to whatever you changed it to.
4. Once you have imported the certificate go back to the Jenkins web interface and navigate to Manage Jenkins –> Configure System and scroll down to the Artifactory section. Input the URL for the artifactory server, the username and the password. make sure to test the connection and click save at the bottom of the page.
Create a repository for our project in Artifactory
I’m going to walk through creating a new Repository in Artifactory for us to store our artifacts that are specific to this project.
1. Login to Artifactory and navigate to Admin –> Repositories and click on the New button on the right next to Local Repositories.
2. On the New Local Repository screen set a Repository Key (Name), choose http-default as the Repository layout, and Check allow content browsing. Click create when done. Your new repository will be listed in the Local Repository Section.
Configuring our Jenkins Item to use Artifactory
In Jenkins we will now edit the Jenkins Item we created in my earlier post. When we finish we will have our generated tar.gz file loaded to our Artifactory repository that we created.
1. In Jenkins select the Item you created and then select Configure. Scroll down to the Build Environment section and select “Generic-Artifactory Integration” Then click on Refresh Repository.
2. Select the Repository that was created earlier in this article for the Target Repository and then in the Published Artifacts box input the name of the tar.gz file that we are creating as part of the build. This is how we tell Jenkins to send the tar.gz file to the Artifactory server. Select Save when finished.
3. Now let’s do a test build and see what happens. On the Project page click Build Now. When it completed you will notice there is an Artifactory symbol next to the completed build. Clicking on it will bring you to the Artifactory server where you can then see information about the build and browse to see the artifact.
4. Next if you select Published Modules, then click on the module you can see the artifact that was published to the Repository.
5. Having the tar.gz with the build number can be handy, but what if you are automating something to pull from the repo that isn’t aware of the build number? We can also upload the latest build with a generic name that doesn’t have the build number in the name. We can do this by adding to our Execute Shell build step on the project. If we make our shell code look like the following we will have two tar.gz file one with the build number and one without.
rm -rf dailyhypervisor.tar.gz
tar -zcvf dailyhypervisor.tar.gz Dailyhypervisor
tar -zcvf dailyhypervisor-$BUILD_NUMBER.tar.gz Dailyhypervisor
We initially delete any previous versions of the tar.gz without the build number and create a new one. This alone however will not put both in Artifactory.
6. To have the generic named tar.gz also put in artifactory update the Published artifacts with both file names comma separated like so:
After saving the change if you run another build you should now see both files as artifacts in Artifactory.
Having a tar.gz without the build number will make it easy for us to grab the tar.gz and use it wherever we like. The files are located at https://atrifactory_host/artifactory/reponame/file.tar.gz making it easy to grab the latest build for any need.