1

Is this possible? Suppose I have 2 jobs. One for building artifact and upload it to artifactory with latest version. And another job to deploy the artifact to the server. But I would like to choose the artifact version. Supose A deploy was made and not working , so I redeploy and choose previous artifact (or the one I want to choose). Is this posible in jenkins in a pipleine project? Like a parametrized build or something like that.

Thanks

enter image description here

enter image description here

Chanafot
  • 736
  • 4
  • 22
  • 46
  • Are you using some jenkins plugin or just shell execution? – JRichardsz Oct 14 '18 at 01:59
  • I have installed the artifactory plug in to upload/download. But I would like to know if there is a way to choose an artifac before build starts. With the artifactor plugin I believe the download or upload is inside code. – Chanafot Oct 14 '18 at 13:47
  • Usage of this plugin is mandatory? – JRichardsz Oct 14 '18 at 13:50
  • If you know the artifact name, you can convert that into a parameter and pass that in your second job. You can find the artifact name from console output or directly in your slave. – mdabdullah Oct 14 '18 at 14:14
  • no JRichardsz is not mandatory but is the only way I know to do this. What are the other options? – Chanafot Oct 15 '18 at 13:01

2 Answers2

1

It will work with the pipelin job . I am it in pipeline job only.

Example: https://wiki.jenkins.io/display/JENKINS/Maven+Metadata+Plugin

  1. Assume that you have 2 jobs .

  2. Job A & Job B. (Both pipeline jobs.)

         Job A -> Build and push the artifacts to Artifactory. 
         Job B -> Fetch the artifact from Artifactory and deploy.
    
    1. Install the Maven Meta Plugin . https://wiki.jenkins.io/display/JENKINS/Maven+Metadata+Plugin
    2. go to Job B
      1. "This build is parametrerized" checkbox, from the drop-down that appears select the "List maven artifact versions",
        configure the artifact you want to retrieve the versions
      2. Name the parameter as deploy_version
    3. In Job B - > Select the version & Click Build.
    4. In pipeline script receive the selected version as param.deploy_version.
    5. Since you know the artifact version and artifact URLs . You can use CURL/httprequest plugin in Jenkisn to download the necessary
      artifact from Artifactory (I am using Maven Ansible artifactory
      plugin to download)
    6. Continue with your deployment.
Samy
  • 632
  • 4
  • 14
  • I´m using a jenkins pipeline proyect, not a maven one, in which the mvn command is executed inside the groovy script in one of the steps of first job: mvn clean compile war:war. I´m looking for a second job that you can manually choose the artifact builded on first job. Is this possible? – Chanafot Oct 15 '18 at 14:05
  • I guess you should push the artifact build during the first job to Artifactory. In the second job configure the above mentioned to list the artifacts from artifactory/nexus. In the second job use the pipeline script to receive the selected artifact and pull it again to deploy it. – Samy Oct 15 '18 at 14:12
  • hmmm is this possible with a pipeline job instead maven? the link you said talks about maven: "JENKINS/Maven+Artifact+ChoiceListProvider+Plugin" – Chanafot Oct 15 '18 at 14:54
  • I Need exactly that but for a pipeline job and not maven job – Chanafot Oct 15 '18 at 14:55
  • @yiyito - I've edited the answer now .Hope its clear now. – Samy Oct 16 '18 at 10:17
  • I edited question. I did What you suggested but I´m getting that error. I edited and upload image with Jenkins and artifactory configuration as I have now. – Chanafot Oct 16 '18 at 15:40
  • it´s something related to maven-metadata.xml what XML is this refering to? I have no such file neither on artifactory nor on the script code. – Chanafot Oct 16 '18 at 15:48
  • I also tried with full URL , inside jenkins configuration , to the artifact group as in second image and got other issue. – Chanafot Oct 16 '18 at 16:23
  • hi unfortunately i can't able to see the attached images due to some restrictions.Please double check the configuration and play around with it. I am sure you can get it. – Samy Oct 24 '18 at 11:58
  • Glad that you fixed the issue. How did you resolved using the plugin i mentioned or found any other solutions? – Samy Oct 25 '18 at 06:46
  • hehe your solutions was great but I needed more detais to do so. but was good for first orientation. Will mark it as accepted man. thanks – Chanafot Oct 25 '18 at 18:56
0

According to this answer :

https://stackoverflow.com/a/34781604/3957754

The artifactory plugin for Jenkins has the option to "resolve" artifacts, i.e. download them from Artifactory. But this may require the Pro version with payment $_$

Download artifact using artifactory jenkins plugin (With Payment)

Download artifact using commandline and maven

Source: How can I download a specific Maven artifact in one command line?

JRichardsz
  • 14,356
  • 6
  • 59
  • 94