Amedee Van Gasse
Amedee Van Gasse

Reputation: 7634

Copy build history from one job to another job

I have a Jenkins job that is a declarative pipeline. It's URL is $JENKINS_URL/job/dnscheck/.

I started using Bitbucket projects on Jenkins, and now that Jenkinsfile is also discovered and the same job lives at $JENKINS_URL/job/website/job/dnscheck/job/master/

I want to copy the entire history (log files etc) from $JENKINS_URL/job/dnscheck/ to $JENKINS_URL/job/website/job/dnscheck/job/master/, and then delete $JENKINS_URL/job/dnscheck/.

  1. Can I do that?
  2. If yes, how do I do that?
  3. I don't want to overwrite existing files

Upvotes: 0

Views: 506

Answers (1)

Ian W
Ian W

Reputation: 4767

On the master, the logs are all stored in ${JENKINS_HOME}/jobs/<path/to/job>/builds/, unless overridden by a system property jenkins.model.Jenkins.buildsDir. They consist of a series of numbered directories with a log file (the build log) inside and possibly some additional data files (eg: build.xml, changelog.xml, injectedEnvVars.txt).

There are also some sym-links for last builds (good/bad, etc.), both inside the jobs directory and inside the builds directory. You could copy all the directories over (renumber if you have conflicts) AND update the sym-links accordingly. You may also need to reset the last build ( Number of builds since the start of the project ) to n+1 so that the next build number increments w/o overlapping. It's in a file inside /nextBuildNumber.

Finally, you must get Jenkins to recognize the new content since Jenkins caches everything. You can do that by either restarting the system, reloading the configuration from disk or less drastically, reload the data on the one job, something like:

def configXMLFile = job.getConfigFile();
def file = configXMLFile.getFile();
InputStream is = new FileInputStream(file);
job.updateByXml(new StreamSource(is));
job.save();

Upvotes: 2

Related Questions