0
votes

I have a requirement,

  1. Create a build Job
  2. Deploy to Artifactory
  3. Download the artifact from artifactory and deploy to test server

All the 3 jobs, I have configured in a Build Pipeline. Also all are having the shared Build path.

This is basically a Java job, I have created the build Job and it is working fine. I have used downstream Job to trigger deploy to artifactory job. It is using Maven build.

In the second job, which needs to be manually triggered (I have configured like that), is running fine and it is getting deployed to respective repository which I have configured. I have used generic artifactory integration plugin and used published artifacts to push to the artifactory repository

Now for the 3rd Job, how to download the artifact from artifactory? If from the 2nd job, we can store the artifactory URL to a file and read it as parameterised build, I am thinking it will work..

But I am not getting any clue to get the artifactory URL.

Please help!

2

2 Answers

1
votes

I was able to achieve this by the below method.


1. Created a Build Job --> This downloads the code from repository and does a maven build. The Pom.xml is adjusted such a way that I get a tar.gz file as output. The information of build number & branch name are saved in a file on the same workspace.


2. Created a Artifactory upload Job --> I used mvn deploy:deploy-file command to deploy the artifacts to speific remote repository in the Artifactory. This has a version parameter, where I pass the build number, and it has groupID & artifactID. So once the maven deploy file uploads the file, it will upload the definite path in artifactory. Since I have all the details already available, I framed the Artifactory URL and it is saved in the same file where I took build number and branch name.

3. Created a Deployment Job to Specific server --> I created a deployment script and kept the script in the server, which takes URL as the parameter. From the file on the workspace I was able to retrieve the URL and did an ssh to the server. Loaded the bash profile and passed the URL to the deployment script. After that it downloaded the artifacts and deployed to server.

Once these jobs are created, I configured the Build Job to take Post Build manual Project and gave Artifactory upload as Job name. And also for Artifactory Job, I gave Deployment as the Post Build Manual project Job.

By this way I created a Build Pipeline view, where all these projects are upstream/downstream project.

0
votes

I think you have missed the point of the pipeline. Original freestyle jobs started to get too complex and have difficult dependencies (like how do I get this url from this job to that job) when chaining them together. The solution to that is to create a pipeline with stages.

stages{
    stage('build') {
        steps {
            //build some stuff
        }
    }
    stage('publish') {
        steps {
                  //publish the stuff
        }
    }
    stage('deploy) {
        steps {
            // download and deploy the stuff
        }
    }

It seems to me that it might be more useful in your case to just deploy the stuff you already have without re-downloading the stuff. Take a look at the stash/unstash steps. These will come in useful between stages.