Copy files from remote Jenkins workspace - jenkins

Im trying to create a cross-compilation job, that will build my code for both Windows & Linux.
I have set up Windows & Linux jenkins nodes, and configured two jobs, one with 'windows' label to run on my Windows machine and the other with 'linux' label to run on my linux machine.
I installed MultiJob plugin, and wrapped both jobs to run in parallel
When both finishes successfully, I want to copy all the generated files and do operations on them
In other words I want to copy the files from both jobs remote workspaces for further operations
Can anyone suggest a way how to do it?

Add your files to the artifacts in your child job (Using "Archive the artifacts" post-build step)
In parent job add build step "Copy artifacts from another project", put you child job name and choose "Build triggered by current MultiJob build" in field "Which build"

Related

Jenkins workspace not shown for concurrent builds on different nodes

I have one job and two slave nodes. "Workspace" is shown in job overview, but it contains only "Workspace of job on slave2". I run two builds on this job in parallel (one build runs on slave1 and one on slave2)
I tried Jenkins 2.74 and 1.658. I use Windows7 for server and slave. I configured Jenkins Job to "Execute concurrent builds if necessary". Description says
Each concurrently executed build occurs in its own build workspace, isolated from any other builds. By default, Jenkins appends "#" to the workspace directory name, e.g. "#2".
The separator "#" can be changed by setting the hudson.slaves.WorkspaceList Java system property when starting Jenkins. For example, "hudson.slaves.WorkspaceList=-" would change the separator to a hyphen.
I also use "Restrict where this project can be run" with: slave1||slave2
How can i display links to all workspaces of all configured slaves at the same time in jenkins web interface, i thought they will be shown as workspace#1 and so on?

Copying files from one directory to another in jenkins

I'm trying to move my test results onto a public webpage.
I set up a "Post-build action" > "Post build task" to execute a script.
The script is:
cp -r /var/lib/jenkins/jobs/instrumentation-tests/htmlreports/HTML_Report/ /var/www/html/test/
Jenkins outputs: cp: directory /var/www/html/test does not exist
If I'm logged in as user jenkins on the linux machine running jenkins, I can navigate to the source and SEE that there are files there currently. I can navigate to the destination and see that it DOES exist.
Also, I tried running that command from the terminal as the jenkins user, and the cp completed successfully.
As you mention in the comments, your test results are being generated during a build on a slave machine. Therefore you're trying to copy the files to /var/www on the slave, not the Jenkins master server.
There are a few different ways you could solve this:
Ensure that the build happens on the master server.
You can do this by choosing "Restrict where this project can be run" on the job configuration page, and entering "master" in the text field.
This ensures that your file copying will work at the end of a build, assuming that the Jenkins user has write permissions.
Use the Publish over SSH plugin to publish the files directly to /var/www on the Jenkins master, from any other machine.
This has the advantage that it will work, no matter which Jenkins build machine the build takes place on.
You could also split up the job into two parts: one job to run the tests and generate the results, and another job to publish the test results.
The first job could run on any machine, and would save the generated HTML files using the "Archive the artifacts" post-build action. It would then start the second job — via the "Build other jobs" post-build action — in order to do the publishing.
The second job could use either of the above approaches: either publish using SSH, or ensure that it runs on the master and use a simple shell step with cp.
In both cases, you would use the Copy Artifact plugin to copy the archived HTML files from the upstream build.

How to copy the artifacts from slave to Jenkins workspace?

I'm running a jenkins job on a slave and i want to store the generated artifacts in the server.Since the job is currently running on the slave the artifacts are also created there.
I tried using post build actions --->archive the artifacts.But it throws the following build error
ERROR: No artifacts found that match the file pattern "**/*.gz". Configuration error?
ERROR: '**/*.gz' doesn't match anything: '**' exists but not '**/*.gz'
Any help in this regards is highly appreciated.
Sounds like Copy To Slave Plugin is what you need
It can copy to slave (before build) and from slave (after build)
Copy files back to master node:
To activate this plugin for a given job, simply check the Copy files back to the job's workspace on the master node checkbox in the Post-build Actions section of the job. You then get the same two fields as for the Copy files to slave node before building section (note that label in the screenshot is old):
if you want to copy artifacts from JobA to the workspace of some other Job, you can do it using the Copy Artifact Plugin which is very simple to understand.
In case you just want to archive the artifacts already in JobA, then you are already in this direction and need to check what you are missing... are you sure that the artifacts are in the current workspace?
Doron

Execute Shell script from workspace on remote machine after build successful (Jenkins)

The scenario is - I have a job A which runs my ant script and packages the artifact's for me.
I am also using parametrized Triggered plug in to Trigger my "Job B" which will deploy my artifact on remote machine.
The job A is working fine and also Job B.
The tasks that i have to perform with Job B are
GIT checkout (which contains my deployment scripts) (successfully doning).
Copying artifacts from previous build to Remote machine. (successfully doing)
Run shell script on remote machine(script present in workspace folder )- Facing issues.
I browsed various plug ins for the same but no one is allowing me to run shell script after , "SCP to remote machine" which is present in Post build action.
I would like to execute the same sequence, however if you guys have any other suggestions please share.
Thanks in Advance.!
As part of Publish Over SSH Plugin, you can execute a script after the files had been copied over.
Under Post-build Actions
Add Send build artifacts over SSH
Select a preconfigured server (done in global configuration)
Select files to copy from workspace
Enter Exec command
If one of the files you copy is your shell script, you can enter it here as an "exec command"
To solve my query i used Jenkins SSH Plugin. This provides a configuration tab where i can add multiple hosts and after that used them in my job level configuration.
Link to Plugin
you get privilege to execute shell script on remote host as pre-build step or post build step.
updated the path of publish over ssh it worked for me

How to copy build XMLs from Master to the Slave node in Jenkins?

I have created a Jenkins job which used to run in the master and I have the build.xml file in the master.
Now I have added a slave node and added the setting Restrict where this project can be run so that my job always runs on a particular slave.
Now my build jobs are failing and I can see:
[EnvInject] - Loading node environment variables.
Building remotely on demo_slave_inst2 (slave1) in workspace /root/slave/workspace/demo_job
FATAL: Unable to find build script at /root/slave/workspace/demo_job/autobvt.xml
Build step 'Invoke Ant' marked build as failure
Recording test results
Finished: FAILURE
This autobvt.xml file already exists in the master. So looks like I need to copy this file over to the slave node manually which does not looks like quite handy.
How I can instruct jenkins to copy this as part of the build?
Use "Copy data to Workspace" http://wiki.jenkins-ci.org/display/JENKINS/Copy+Data+To+Workspace+Plugin using which you can copy the files from master to slave and run them as a part of build process (No manual effort needed!)
I sorted the issue using the Copy to Slave plugin.

Resources