Can Jenkins store artifacts outside the job directory?
Asked Answered
M

6

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)

Magdamagdaia answered 28/2, 2012 at 13:50 Comment(0)
O
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.

Olav answered 2/1, 2014 at 11:27 Comment(1)
Seems like the newer versions of Jenkins no longer support the 'advanced' option in the UI. SourceAlack
L
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.

Latreese answered 28/2, 2012 at 13:58 Comment(4)
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."Magdamagdaia
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.Paulownia
Problem is, I was wanting to avoid having it in the job directory, but still have the artifacts linked from the job status page.Magdamagdaia
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.Tart
I
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.

Incommodity answered 25/11, 2018 at 13:5 Comment(0)
E
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.

Eschew answered 7/1, 2013 at 13:18 Comment(0)
A
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

Acknowledgment answered 25/9, 2018 at 11:26 Comment(0)
H
-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.

Huei answered 24/7, 2013 at 11:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.