80

I have a job called "development" and another project called "code analysis". At the moment we have two different jobs and different workspaces, but same code; is there any way we could use the same workspace for multiple jobs?
I checked the plugins available in Jenkins but I haven't found any suitable one.

3
  • 3
    you can use a custom workspace stackoverflow.com/questions/20537137/… Feb 3, 2014 at 7:05
  • 4
    If you do use the same workspace, you will want to make sure you don't have concurrency and that you can properly track revisions between the two. A concurrency could happen if you are in the process of analyzing code when the development job starts checking code out. There are plugins (and answers) on how to prevent the issues on this site. (Full disclosure: We tried a common workspace and decided it worked better for us to use the clone workspace plugin with separate workspaces.)
    – jwernerny
    Feb 3, 2014 at 13:15
  • 1
    To do this concurrency easily, trigger the analysis job from the development job, and check the Advanced Project Option "Block build when upstream project is building" on the analysis job.
    – Paul Hicks
    Feb 3, 2014 at 23:04

4 Answers 4

89

Suppose your "development" Jenkins job workspace is /var/workspace/job1. In the "code analysis" job configuration page, under the tab General click on Advanced... and select the option Use custom workspace and give the same workspace /var/workspace/job1 as of your "development" job.

5
  • 25
    This is a decent path... but I'd take it once step closer and use the wiki.jenkins-ci.org/display/JENKINS/inheritance-plugin to inherite ${WORKSPACE} so it doesn't have to be hardcoded in all the jobs - it will be cleaner to maintain.
    – thekbb
    Feb 3, 2014 at 16:33
  • 5
    @thekbb, that would be an option, except for the Stack Overflow that occurs when used in conjunction with JobConfigHistory plugin. Until the maintainer corrects that issue, it's useless to anyone that needs the JobConfigHistory plugin for jobs that don't use inheritance...
    – Jon L.
    Oct 7, 2014 at 13:57
  • The workspace directories differ between master (job/<jobname>/workspace) and slave nodes (workspace/<jobname>. So the hardcode involves a script as well as the plugin. Jul 8, 2015 at 18:43
  • It would appear that the stackoverflow is still an issue according to wiki.jenkins-ci.org/display/JENKINS/inheritance-plugin
    – Rob Kielty
    Mar 22, 2016 at 12:13
  • 1
    FYI that in Jenkins version 2.147 to set custom workspace go to General tab of your project, than click Advanced... button and you will see "Use custom workspace" check box.
    – Lyserty
    Mar 11, 2019 at 20:57
8

if you were not able to find Use custom workspace you can located it under your project configure>General>Advanced>Use custom workspace

6

There is a Jenkins Plugins which enables you to create a shared workplace a setup them on every job which need the files from that given repository.

Use Case:

Similar to what you need, first create two jobs from the same Git Repository, then go to "Manage Jenkins" and you create a Shared Workspace. And point to it, on every job you need to read from that files.

Jenkins Plugin

https://wiki.jenkins-ci.org/display/JENKINS/Shared+workspace+plugin#


PS: You should look into "Known Issues" could be a deal breaker for your needs.

sometimes, on fresh copied job, shared-space url parameter not saving to config on first "save", you should save job twice to be sure.

^^ This one it's still unresolved, I tried and still happens. After some several saves (just to be sure) the job runs perfectly.

2

I tried the inheritance plugin and whoa! that thing is a sledgehammer when all I have is a tiny nail.

I ended up adding a Post-build Action of "Trigger parameterized build on other projects" with "Build on the same node" and a "Predefined parameter". The downstream job needs to have a parameter of the same name defined (WORKSPACE_PARENT) but you can leave it blank. You then define the downstream job with a custom workspace (under General > Advanced)

I chose a post-build action because the actual success of the build job is independent on the results of the downstream build (for now). If you want to bump the results of the downstream job up to the parent job, you need to add it as a build task, not a post-build action.

It works great for what I need.

Parent's post-build task: Parent's post-build task

Child's custom workspace: Child's custom workspace

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.