Jenkins: Copy data from slave to slave - jenkins

let's say we have got the following scenario:
I have two slaves on Jenkins: S-1 und S-2.
I have two Build Jobs BJ-1 und BJ-2. (BJ-1 is running on S-1, BJ-2 on S-2.)
BJ-1 generates data in his workspace
BJ-2 needs the data created bey BJ-1 in his own workspace
How can i solve this problem WITHOUT copy all the data to my master. I know i can copy the data of BJ-1 on S-1 to my master server, once the job is done and i also know i can download the data to S-2 before BJ-2 runs. But as you see i have to copy them to my Master.
The question: Is there a way to directly copy the data from S-1 to S-2?

Best way to achieve this is to archive your generated data in the post build steps in BJ-1 and copy then artifact to BJ-2 workspace.
BJ-1
Archiving artifacts is built in to Jenkins and allows you to define a file set to be available as part of the build results. Extend BJ-1 to configure what data should be archived . With that the archived data is available for further use.
BJ-2
In order to pick up the archived artifacts from another job you will need to install the Copy Artifact Plugin. In BJ-2 you add a new build step to copy artifact from a named build - with that any files matching the configured pattern will be copied into the current job's workspace. With that you can access any kind of artifacts across jobs/slave nodes etc.

Related

How can I use Artifact Deployer to copy from the archived artifacts, instead of the workspace?

We've been using Jenkins for a while, now, and have used the ArtifactDeployer plugin to copy build artifacts out of the working directory to our artifact repository fileshares.
I'm working on a new deployment promotion job, that needs to obtain the artifacts of a given build, and I thought I might use the Copy Artifact plugin. But that expects that the artifacts be saved using Jenkin's artifact archive feature, which we've not been using.
There are some nice features, in the Copy Artifact plugin - we can configure it to specify the upstream build that triggered the job, rather than having to pass a specific build number as a parameter. But to use it, we'd need to configure archive.
But we still need to copy artifacts to our artifact repository fileshares, which means we have to specify the files we want to archive twice - once in the archive config and once in the ArtifactDeployer config.
Unless we can configure the ArtifactDeployer plugin to copy the contents of the archive directory.
Is this possible?
What would be the path?

Copy artifacts from other job only if there is new version of file

We have a master and two slaves.
On Master there is a job which checks if there is new version on Nexus and if yes downloads latest jar and updates latest version (i.e. xxx-0.012.jar) in text file VERSION.TXT. (It is possible to access nexus only from master).
We need to run downloaded jar on slaves so we need to copy it from master.
We have a job which triggers few other jobs:
1)CHECK_LATEST_JAR: job which runs on master and checks if there is new version of jar on nexus, downloads it.
2)GET_JAR_TO_SLAVE: job which runs on slaves and should copy latest jar from master
3)RUN_JAR: job which gets latest jar name from file VERSION.TXT and runs jar with such name.
In CHECK_LATEST_JAR if newer version is found on nexus we download it to workspace and archive artifacts (jar + text file with latest version).
Now in GET_JAR_TO_SLAVE we wanted to use "Copy artifacts from another job" plugin - but here we need to add a condition to run this step only if there is newer version as if there are no artifacts in CHECK_LATEST_JAR this job fails..
Is there a way to compare file which is located on master with file which is located on slave?
Tried to use conditional step with groovy script - but cannot figure out how to tell it to access file on master if job runs on slave.
Just came across FSTrigger plugin which probably can be used - but same problem here how to tell it to monitor file VERSION.TXT on master and if there is a change to run job on slave.
would be grateful for any ideas how we can achieve our goal.
thanks
We found plugin Copy Data to Workspace and used it to copy file containing latest version from folder on Master to workspace of job running on one of slaves.
After that we compare content of files using Conditional BuildStep plugin strings comparison with Token macro and if files content is different we copy artifacts of the job where jar is downloaded.

Creating artifacts in jenkins

I have been tasked with looking into using Jenkins as a build server. So far I have managed to pull a project from git, restore the Nuget packages, build the project and run the unit tests. However I am struggling to find out how to generate the artifact.
The way the business would like to have the build server generate a zip file to a directory on the build server or a remote server for the systems team then to pick up and deploy to the relevant location. E.g. given a windows service project the built bin directory would be zipped up and put in the relevant artifact directory.
I thought that in order to do this I add an archive the artifacts post-build action. However I am getting the below error:
‘Watchdog.WinService.Monitor/bin/Release/*.zip’ doesn’t match anything:
‘Watchdog.WinService.Monitor’ exists but not
‘Watchdog.WinService.Monitor/bin/Release/*.zip’
If I look in the workspace for this project I can browse to the bin directory and see all the files so I unsure what I have done wrong.
Can someone please let me know if what I am trying to accomplish is possible, and also if our approach to using Jenkins is correct?
The problem is that you try to create the artifact using the archive artifatcs step.
But the step is to collect artifacts and show them on the job page.
That means you need to create the artifact first e.g. using a shell or batch script.
You can combine this with the Flexible Publish Plugin.
When you select this as post build step you can create a conditional action that runs the artifact archive task and as condition executes the script that creates the zip file.
So if that fails the task won't be executed. Also it may causes your job to 'fail' but that may not be the case in your job.

Can a Jenkins build access the archived artifacts from itself?

I'm using Jenkins and have the "Archive the Artifacts" step at the end of my builds to archive them into a zip file.
Instead of using this step, I'd like to use a script to push the artifacts to a remote server at the end of the build. The server I'm pushing to uses a REST API / HTTP PUT request in a script to upload files.
Note that I'm looking to access the artifact created in the same build. So if I'm on build #5, I want the artifacts from build #5, not build #4.
Is there any way to access this zip file with a script, in the same build that it was created in?
I need to upload this zip remotely and don't want to create another job to do so.
You can install one of the "Publish Over..." plugins to upload your artifacts at the end of a build.
The goal of the Publish Over plugins is to provide a consistent set of
features and behaviours when sending build artifacts ... somewhere.
See also the full list of "upload" plugins for other methods of publishing your artifacts.
Like #Christopher said, you can use any of the Publish Over plugins on the Jenkins Plugins page to upload the artifact to any of the
If you want to access the archived zip file from within the build itself, you can use the following link to access it:
http://<server>/job/${JOB_NAME}/lastSuccessfulBuild/artifact/<artifact name w/folder>
For example:
server = myserver.com
job name = myproject
artifact = del/project.zip
Your URL would be:
http://myserver.com/job/myproject/lastSuccessfulBuild/artifact/del/project.zip
EDIT: Question was changed. In any case, this would work for accessing the artifact of the previous build in the current one.
There is no way that I have found to access the "Archive the Artifacts" package of the build that generates it. This step always occurs last in the build. Accessing the URL prior to the build ending (during the build via script for example) results in a blank zip file. To get around this limitation, I'm making a second linked build job to grab the zip and run my script to deploy it.

teamcity ant multuple project build

I hope you guys can help me.
my problem is the following:
i have 2 projects that depend on each other each of them in different svn root.
what i do toady is build the first , take its artifact and copy it manually to where ever i want in second project and than run the second build.
i want to be able to run 1 build it can be either with a new ant build.xml file who will run the first build , copy its product to where ever i want it and than will run the second build.
second option run those 2 project with dependency in teamcity. i'm not sure how to do so and how to pass the first project artifact to be placed in the right folder i need it in the second project.
maybe someone know's how to do that.
thanks.
TeamCity's Artifact Dependencies seems to be the best option.
Suppose you have ProjectA and ProjectB:
Configure TeamCity to publish files from ProjectA:
Open General Settings configuration step of ProjectA.
Fill in Artifact paths field with relative paths to published files. TeamCity will collect these files after build finishes.
Build ProjectA to make sure artifacts are collected properly. Artifacts must become available on build results page (see Artifacts tab).
See documentation for artifacts for more details
Configure Artifact dependency for ProjectB:
Open Dependencies configuration step of ProjectB, add new artifact dependency
Depend on - select ProjectA
Get artifacts from: - use whatever you need. Possibly, last successful build.
Artifacts - enter artifacts paths from ProjectA. You can use popup to choose artifacts with UI.
Destination path - enter destination path, where artifacts will be copied to. Path is relative to checkout directory
See documentation for artifact dependencies for more details
Now each time you start build for ProjectB, it will download artifacts from last successful build of ProjectA. If you want these builds to start simultaneously, add Snapshot dependency (on ProjectA) to ProjectB. With snapshot dependency, each time you start ProjectB, it will first trigger ProjectA, wait for ProjectA build to finish and (if has artifact dependency on "last successful build" of ProjectA) download fresh artifacts.

Resources