choose artifact from artifactory to deploy pipeline job in Jenkins - jenkins

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

It will work with the pipelin job . I am it in pipeline job only.
Example: https://wiki.jenkins.io/display/JENKINS/Maven+Metadata+Plugin
Assume that you have 2 jobs .
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.
Install the Maven Meta Plugin . https://wiki.jenkins.io/display/JENKINS/Maven+Metadata+Plugin
go to Job B
"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
Name the parameter as deploy_version
In Job B - > Select the version & Click Build.
In pipeline script receive the selected version as param.deploy_version.
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)
Continue with your deployment.

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)
Configure your artifactory plugin
https://medium.com/#anusha.sharma3010/integrating-jenkins-with-artifactory-6d18974d163d
https://www.jfrog.com/confluence/display/RTF/Jenkins+Artifactory+Plug-in
In resolve section, you could download your artifacts
Download artifact using commandline and maven
configure maven and artifactory authentication
https://docs.gitlab.com/ee/ci/examples/artifactory_and_gitlab/
https://blog.bosch-si.com/developer/setting-up-maven-and-artifactory/
download artifact from artifactory
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-DrepoUrl=http://my_artifactory-url.com \
-Dartifact=groupId:artifactId:version
Source: How can I download a specific Maven artifact in one command line?

Related

Jenkins Artifactory Plugin: upload custom files in the middle of the a build

How can I upload files to an Artifactory by Jenkins Artifactory Plugin in the middle of the build? After uploading, the job will trigger another job which will download the artifact from the Artifactory. Arching artifacts in the Jenkins jobs is not an option for me because we should keep artifacts in Artifactory.
I could use curl to upload to the Artifactory, but I need to have old builds discarding (by Jenkins Artifactory Plugin). I could use "Generic-Artifactory Integration" in the jobs configuration, but it uploads only at the end of the job build.
We have used the jfrog cli to do this on generic jobs. Be sure to include the —build-name and —build-number options to have your artifacts collected correctly when the Artifactory plugin publishes the build info.

How to check which jenkins job is responsible for an artifact upload in artifactory

We have a lot of jenkins jobs (400+). A lot of them are uploading new artifacts to our Artifactory. Most of them are using the Artifactory plugin.
When we use that plugin we can check the 'build browser' in Artifactory.
This will show the jenkins jobs which are uploading artifacts with that plugin. It's clear.
The problem is that we also have some jobs in which case it isn't useful for us to implement the artifactory plugin. Is there a way in Artifactory we can check those jobs?
We want to see from an artifact which is uploaded WITHOUT the artifactory plugin from which jenkins job it's coming from.
Jenkins jobs that use the jfrog cli to upload artifacts can now also publish build info.
From the jfrog cli help
JFROG_CLI_BUILD_NAME
Build name to be used by commands which expect a build name, unless sent as a command argument or option.
JFROG_CLI_BUILD_NUMBER
Build number to be used by commands which expect a build number, unless sent as a command argument or option.
JFROG_CLI_BUILD_PROJECT
Artifactory project key.
JFROG_CLI_BUILD_URL
Sets the CI server build URL in the build-info. The "jfrog rt build-publish" command uses the value of this environment variable, unless the --build-url command option is sent.
Setting these environment vars during the Jenkins job and then calling
jfrog rt build-publish will allow you to connect the jobs to the artifacts.

How to configure jenkins to upload build artifact to nexus?

I have jenkins jobs that builds ios and android app and i want jenkins to upload those artifact to nexus after build is done.Is there any way to do it?
Thanks
If you are building the apps with Maven or Gradle or whatever (esp. the Android ones) a simple mvn deploy or gradle uploadArchives will do the trick. Same applies if you build the ios app with one of these tools.
In most other cases you can always do normal upload via the REST API.
Examples for the Maven and Gradle setup are in the eval guide and the examples to the Nexus book.
Use the Nexus Artifact Uploader Plugin, and set up a new job where you set a build step to Copy artifacts form another project, and a step to Upload artifact to Nexus

Publish to Artifactory copied from another project artifacts in Jenkins

So I got few separated jobs in Jenkins. The first one gets the project from a Git repository, builds it and produces artifacts. And another one has to copy certificates from the first job and publish them to Artifactory (tried to make it using the Artifactory plugin). But the thing is that the Artifactory plugin's available only in the Build job, there's nothing like "Generic-Artifactory integration" in second job's configuration.
Does anyone know what are the requirements for making the plugin work in the Publish job?
You can write a small shell script leveraging Artifactory REST API and execute it in your second, non-build job.
I have done a similar thing with maven and a zip file. I have deployed a zip with a build step in maven calling a deploy:deploy-file and setting my Artifactory repository in settings.xml and deploying directly on my artifactory repository.

Upload multiple Gradle artifacts to Artifactory from Jenkins

My environment uses Gradle for builds, Jenkins for CI, and Artifactory for a repository. I use the Artifactory plugin for Jenkins.
Jenkins successfully builds my main jar file and uploads it to Artifactory. The build script has a second target for creating a distribution zip file under build/distributions. Jenkins creates the zip file successfully, but I don't know how to tell it to upload that artifact to Artifactory, too.
Is this something I should be able to specify in the Jenkins Artifactory plugin config, or something I should define in the Gradle build script? Thanks for any pointers.
You should configure the archives configuration to include all the archives you intend to publish as described in Gradle's user manual. Not only Artifactory will pick up all the files to deploy automatically (without messing with Published Artifacts configuration), you won't even need to run the second task. All the archives will be creating by running the build task.
I assume you have configured artifactory server correctly in Manage Jenkins section; also your job is setup as a Freestyle Project.
Select your job and click Configure. Check Generic Artifactory Integration in Build Environment. Select your Artifactory Server and Target Repository from drop downs, check Override default deployer credentials if required. In Published Artifacts you enter the pattern for your zip file to be published, e.g. ${WORKSPACE}/distr/*.zip (where by WORKSPACE is jenkins current project's workspace and distr/*.zip your distribution zip file). Check if required Capture and publish build info, Include environment variables etc. Save your job. When you build it the next time, the zip file will be uploaded and will be available in the Builds section on artifactory.

Resources