How to delete specific file from workspace post build? - jenkins

I have a Freestyle project where I want to delete some files from the workspace after the build is finished. I tried the post-build step Delete workspace when build is done with an include pattern, however no matter what pattern I use the step is successful but the file is not deleted.
I tried
config.ini
/config.ini
'config.ini'
${WORKSPACE}/ProjectRoot/config.ini
and some more wild guesses, but nothing worked.
Console output for the step
...
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] done
...

Related

How do I tell Jenkins to automatically create #tmp directories?

I'm using Jenkins on Windows with the Windchill RV&S (Integrity) configuration management plugin. I've noticed that from time to time, it deletes the #tmp directories for project workspaces, but it won't recreate them. i.e. if I have this directory structure:
C:\PTC\workspace\Project1
C:\PTC\workspace\Project1#tmp
Then sometimes the build will fail when C:\PTC\workspace\Project1#tmp goes missing. I don't know why Jenkins deletes it. Maybe it happens when I enable the cleanCopy option in my pipeline? The build failure message is usually something like this:
C:\PTC\workspace\Project1\build>make
..\..\path\to\compiler ..\..\path\to\source_file.c
#error compiler ..\..\path\to\source_file.c:0 can't create C:\PTC\workspace\Project1#tmp\s634.cx1
..\..\path\to\source_file.c:
make: Error code 1
So I re-create C:\PTC\workspace\Project1#tmp manually and the build works again. How do I tell Jenkins to create these #tmp directories automatically?
Edit:
My builds are happening daily (#midnight). They'll work fine for about a month or so, and then on the same day, all the #midnight builds will fail. Each #midnight build will lose its respective #tmp directory and every file in its workspace will be gone (but all the directories will remain). To recover from this, I have to manually recreate the #tmp directory and specify the cleanCopy option (otherwise Windchill RV&S won't restore the missing files in the empty workspace directories).

Copy files from slave to master in Jenkins?

Copy to slave plugin using Here running slave and copying file *.app from slave to master. so In Post build action selected an option to Copy files back to the job's workspace on the master node. Now, in Option files to copy added .app but files are not been copied.
Logs are printed as below :
[copy-to-slave] Copying '.app', excluding nothing, from 'file:/C:/JenkinsSlave/workspace/abc/PLATFORM/iOS/' on 'hudson.slaves.DumbSlave[ slave]' to 'file:/mnt/jenkins/builds/workspace/abc/' on the master.
so on above path file are not being copied. Any suggestion and solutions are welcomed. Thanks
Under Jenkins write the actions as below:
Post Build Action
Copy files back to the job's workspace on the master node
Files to copy - **/.app

Where is the copied artifact from the previous build saved

I have two jenkins jobs which are chained. The first job will run some testNG tests , in which we may get some failures. (A testng-failed.xml file will be generated that has all the tests that failed). In my second job, I need to run using that testng-failed.xml as my suite file. So I am using jenkins copy artifact plugin and saving the testng-failed.xml file. I am able to retrive it in the second job , where it says "Copied 1 artifact from "rerun_exp" build number 7".
But the problem is I dont know where it is saved to be used as my suite file.
You can easily check where the file is by looking in the workspace.
This can even be done directly from the Jenkins web UI, via the "Workspace" link in the sidebar of the job page.
Files matched by the "Artifacts to copy" field are copied to the same directory structure as the source build had.
You can use the "Flatten directories" option if you want the file(s) to be copied to the root of the build workspace. If you click the (?) help icon to the right of that checkbox, you can see documentation for this and for your original question.

File not found exception while reading .js file within jenkins workspace

I am facing a weird issue here. In my jenkins job I've configured it to pull my project's source code from artifacts. So I get 2 directories in workspace called classes and resources. Now some of my tests are failing with FileNotFoundException, stating ABCD.js not found in the given path. When I check this path in the jenkins workspace, this file exists there.
I am not sure about the problem. However, there are following tasks which I've added in the build steps.
1. Download the jar from the artifacts.
2. Unjar the downloaded jar in workspace.
3. Run the tests in the workspace.

Archiving artifacts not in the workspace when build fails

When an ANT build step fails in my build I'd like to archive the logs in order to determine the problem. The relevant logs, however, are not located in the workspace, so I have to use a full path to them.
The standard artifact archiving feature does not work well with full paths, so first I have to copy the logs into the workspace within some build step so that I can later archive them. I do not want to incorporate the copying code into the original ANT script (it does not really belong there). On the other hand, since the build step fails the build I can't execute the code that copies the artifacts into the workspace as a separate build step as it is never reached.
I am considering using ANT -keep-going option, but how will I then fail the build?
Any other ideas (artifact plugins that handle full paths gracefully, for example)?
Update: I've worked around the problem by creating a symbolic link in the workspace to the directory that contains the files to be archived. Kludgy, but effective.
I would recommend using Flexible Publish plugin in conjunction with the Conditional Build Step plugin.
The Flexible Publish plugin allows you to schedule build steps AFTER the build steps have normally run. This allows you to catch both successful and failed builds and execute something - say a script that copies the files from OUTSIDE the workspace to INSIDE the workspace. The Conditional BuildSet plugin allows conditionalizing the steps so that they only run when the build fails. Using these two plugins, you can copy the files into the workspace upon failure, then archive them with the usual Jenkins mechanisms.

Resources