15

I currently have Jenkins set up with a number of jobs, but it's proving difficult to back up because the artifacts are stored within the job directory. I'd like to back up the job configurations and artifacts separately. I'm sure I remember reading somewhere that Jenkins now has an option to store them outside the job, but I can't find this.

Is there any configuration option that does this while still making the artifacts visible from within the job on the Jenkins interface? (ie rather than merely an add-in that copies the artifacts elsewhere)

the_mandrill
  • 29,792
  • 6
  • 64
  • 93

6 Answers6

12

Go to your jenkins configuration page, e.g.

http://mybuildserver.acme.com/configure

At the top of the configuration page there is a "home directory" setting. Click the "advanced..." button below it.

Now set the "Workspace Root Directory" to e:\jenkins-workspaces\${ITEM_FULL_NAME}, and "Build Record Root Directory" to e:\jenkins-builds\${ITEM_FULL_NAME} or something similar.

Warning: I run Jenkins 2.7.2 and noticed that certain features don't work properly after configuring Jenkins like that. I saw problems with folders and problems with the multi-branch project plugin. Check the status of those issues if your rely on these features.

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
  • 3
    Seems like the newer versions of Jenkins no longer support the 'advanced' option in the UI. [Source](https://jenkins.io/doc/upgrade-guide/2.121/#ui-option-for-custom-builds-and-workspace-directories-on-the-master-has-been-removed) – Adam Oct 26 '18 at 14:23
7

As you can see here, there are many plugins to deploy artifacts anywhere you want/need, on FTP, CIFS, Confluence, Artifactory.... especially the ArtifactsDeployer that will allow you to make a copy of the artifacts in the Jenkins Home.

Cédric Julien
  • 78,516
  • 15
  • 127
  • 132
  • 2
    Thanks, looks useful, but I suspect that the ArtifactsDeployer won't do exactly what I need as it says, "due to the Jenkins design, it's not possible for example, to extend the 'archived artifacts' feature to archive artifacts in other locations." – the_mandrill Feb 28 '12 at 15:23
  • 1
    Take a second look at ArtifactDeployer. It can COPY the artifacts to another location, like on the network. And there's an ADVANCED option "Delete remote artifacts when the build is deleted" that will also delete the files when the build is deleted. Now, you really have two copies of the artifacts: one in the Jenkins job/build directory, one on the network. – Jason Swager Feb 28 '12 at 15:36
  • 3
    Problem is, I was wanting to avoid having it in the job directory, but still have the artifacts linked from the job status page. – the_mandrill Feb 28 '12 at 18:32
  • Artifactory's plugin maintains a badge link on each build run to it's corresponding build info in Artifactory, if this is of any help. – noamt Feb 29 '12 at 07:14
2

Thank you Sam, for your post, which directed me into the right direction to solve my problem. Have been searching for a way on how can I make a symlink to the Job-Archive of a build for multibranch projects. Up to now, we used to manually search for the correct folder basename in the filesystem and added that one to the Jenkinsfile. Now, I can simply use

jobOutputFolder = currentBuild.rawBuild.artifactsDir.path

and use that in my script. If security is a concern, I could implement that as a shared library additionally.

schlm3
  • 108
  • 7
1

Try the Use Custom Workspace build option. From the Jenkins popup help:

For each job on Jenkins, Jenkins allocates a unique "workspace directory." This is the directory where the code is checked out and builds happen. Normally you should let Jenkins allocate and clean up workspace directories, but in several situations this is problematic, and in such case, this option lets you specify the workspace location manually.

This option is also available under advanced project properties of multi-configuration project builds.

Justin Rowe
  • 2,356
  • 1
  • 20
  • 15
1

A groovy script under "Prepare an environment for the run" will always run on the master, and this groovy script can create a symlink to where you really want artifacts archiving to archive_to which SHOULD include the job name and build number:

if (! Files.createSymbolicLink(Paths.get(currentBuild.artifactsDir.path),
                               Paths.get(archive_to.getCanonicalPath()))) {
  throw new RuntimeException("Can't create symlink to archive dir")
}

Of course (sadly) when old builds are purged by Jenkins the old artifacts are left because jenkins will not follow a symlink when purging, even if jenkins owns the symlink and the target (shame).

I workaround for that may be to point a symlink back from the new archive dir, then, when jenkins purges it's archive dir, the new symlink will dangle and a cron job can then later delete the new job archive dir

Sam Liddicott
  • 1,265
  • 12
  • 24
-1

Copy Artifact Plugin (https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin) adds a build step for retrieving files from another project's workspace to current and work from there.

jmu
  • 3,619
  • 1
  • 23
  • 12