Load dependencies in Jenkins - jenkins

I am using Jenkins for building a few Java projects. I've come across a puzzle that I can't quite figure out: I have two projects, Project A and Project B. Project B depends on having A as a library. I don't want to build A before B. I want B to find the latest, promoted Project A.jar and copy it to a folder in the Project B workspace. What's the best way to go about this?

You can configure Jenkins to add a post build step to archive artifacts (your JAR file in this case)
Then use the copy artifact plugin in your second project to fetch the artifact https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin

Related

Jenkins copy artifacts from another project

I moved a job that does an update function from one project to another. Under the configure option i used the copy artifacts from another project and updated the tab with the project name from which project it needs to pull files from and hit save. When i run build on the job, it does not pull the files that it needs to from the intended project and the build fails. Am i missing anything on this?

TFS - Multiple builds feeding a single release

I have 2 builds (A & B), which create their own artifacts which are dropped into the $(Build.ArtifactStagingDirectory) and then published to 'Visual Studio Team Services/TFS'
Everything works fine for build A, but I am finding that when I am wanting to download an artifact from build B, that artifact cannot be found. When I look at the error message, I can see that TFS is actually looking for it from build A.
I dont want to point to a specific build number for build B, instead just want to point to the latest build of B.
Anyone know how I can update the reference so that TFS is looking at build B?
If I use the 'Download Artifact' Task, I can get this to work if I point to a 'Specific Build', but it does not work if I use the option 'Current Build'
Try below steps to achieve that:
Create 2 build definitions to queue Build A and B :
Build Definition A -- Build A
Build Definition B -- Build B
Create a release definition, add Build Definition A and Build Definition B as the artifacts source.
Trigger the release
Release works with multiple artifacts:
UPDATE1:
The Download Artifact task only works on single artifact, multiple artifacts doesn't work.
Besides, why you have to use the Download Artifact task? By default the release definition has enabled the Download Artifact, that means it will download the multiple artifacts automatically, then you just need to use the multiple artifacts directly in other tasks.
UPDATE2:
Since you already linked multiple artifacts in your release definition, that means you have to download them to use on subsequent Phases/tasks. But based on your description seems you want to use the Download Artifact task to down the latest version of one of them. That seems a bit contradictory for your requirements.
I can think of is that you can download the artifacts to a staging folder, then add copy task to copy the artifacts which you need in your phases.
Besides if you want to download all the latest artifacts, you can try this extension: Download Artifacts

Jenkins switch build folder

I'm not even sure if I'm thinking about this correctly so I'm having difficulty googling it. I've got Jenkins set up and building a site and correctly sending the build artifacts over SSH to the live server.
My ideal workflow would be to ssh into the server, drop the new assets into a build folder, copy the old build files to a backup directory and drop all the new build files where the old build files used to be.
Not sure if that even makes sense or if there is a better way to do this. To be clear, I'm not talking about a single .war file or anything. I'm talking about a package of PHP files, images, CSS and other stuff.
I'm new to Jenkins in general so any help pointing me in the right direction is greatly appreciated.
See the ArtifactDeployer Plugin:
ArtifactDeployer plugin enables you to archive build artifacts to any remote locations such as to a separate file server.
...
ArtifactDeployer is a complete alternative to the built-in Jenkins feature "Archiving artefacts' and it is aimed at providing an uniform deployment mechanism.
Add it to your project's config with Post-build Actions → Add post-build action → [ArtifactDeployer] - Deploy the artifacts from build workspace to remote locations.
or the Flexible Publish Plugin:
...
[Send build artifacts over SSH]
...
Add it to your project's config with Post-build Actions → Add post-build action → Flexible publish.
or an idea I haven't tried myself yet, so no guarantees:
Configure your live server to be Jenkins slave node, create a project that is bound to this slave and use the Copy Artifact Plugin therein:
Adds a build step to copy artifacts from another project.
Add it to this project's config with Build → Add build step → Copy artifacts from another project.

How to build several projects with dependencies

I have workspace with n projects. I want to use ant to build all the projects with one command. The projects are depend on each other
For example project A depends on project B, so I want B to compile first When I compile project An I need to use B's project classpath.
The dependencies between the projects are represented in a ivy.xml file
The main challenge is that I have my own repository where all those projects have artifacts, and using the example I just gave Project A compiles against the B project coming from my the repository and not Against the B project that just was compiled.
I use CI process and I don't want to publish any project to my repository before all of them compiled and the the the QA tests was passed
What is the best practice build several projects with dependencies using ant?
You can combine the ivy buildlist task with subant to build the sub-projects in the correct order, based on dependencies.
See the following answer for an example:
ivy simple shared repository
Using this approach it's possible to re-create how Maven works without switching build tools.
You can spend a significant amount of time fighting ant and ivy in order to achieve what you want, or you could just use Maven or Gradle which will handle all of this for you automatically.

Build multiproject Gradle on Jenkins

I have a Gradle multiproject hosted in Mercurial repo. I would like to setup my Jenkins in such a way, that if I commit changes into only 1 subproject, then only that subproject will be built and published to my Nexus repo.
Can somebody give me a hint? Or is it at all possible?
We sort of have this working.
We create a project in Jenkins for each gradle subproject. And in the Jenkins configuration we build only the subproject by doing something like:
gradle clean :<subproject>:build
We still have the problem that the job is fired for all checkins to the entire project. I would to configure Jenkins to build only when there's checkin to the subproject, but don't know how to specify this.
Leaving our final solution for the future here.
We created a separate Jenkins job for each subproject. Jenkins' Mercurial plugin allows to specify "modules":
Reduce unnecessary builds by specifying a comma or space delimited list of "modules" within the repository. A module is a directory name within the repository that this project lives in. If this field is set, changes outside the specified modules will not trigger a build (even though the whole repository is checked out anyway due to the Mercurial limitation.)
This way our jobs are triggered only when change occurred in the monitoring sub-project.
I guess you need to create a project in jenkins for each subproject.
Other option would be to find if there is a way to intercept the repo sync and see what subproject has changed and do the build dynamically.

Resources