9

I am running multiple instances of the same job concurrently, and it creates multiple workspaces. However, I am only able to "view" one workspace from the Jenkins web interface.

Example: Let's say the job name is jenkinsJob. Running it concurrently creates workspaces "jenkinsJob", "jenkinsJob@2" and so on. Jenkins web interface only shows "jenkinsJob" workspace at the job level only. Morever, "jenkinsJob" workspace shows only the files of the instance that completed last. So, if "jenkinsJob@2" completed last in the concurrent execution, the "jenkinsJob" will show the files for "jenkinsJob@2".

Could someone tell me how I can "view" all the concurrent workspaces on the Jenkins interface?

techjourneyman
  • 1,701
  • 3
  • 33
  • 53

5 Answers5

2

I didn't find any available plugin for this, but you can use subfolders in the job's workspace.

  1. Setup a single custom workspace for each build:

enter image description here

  1. Use "Execute Windows batch command" build step with the following content:

    1. Create %BUILD_NUMBER% folder under %WORKSPACE% directory
    2. Copy your project files to %BUILD_NUMBER% directory
    3. Go to %BUILD_NUMBER% directory
    4. Build your project with ant:

      %ANT_HOME%/bin/ant {ant_target_list}
      
  2. Explore result for each build in job's workspace:

enter image description here

Note:

  • concurrent builds are still safe as they are executed in different folders
  • you will need to cleanup your workspace periodically
Vitalii Elenhaupt
  • 7,146
  • 3
  • 27
  • 43
  • Thanks @Vitalii. For step #2, could you please tell which script you are referring to here? – techjourneyman Jul 03 '15 at 04:20
  • @naspras I mean build steps of your job (build script). – Vitalii Elenhaupt Jul 03 '15 at 22:32
  • Sorry @Vitalii, but I did not entirely understood the step 2. My build script is an ant script that runs a bunch of targets in sequence. The build script lives "under" the workspace's main directory. Also, are you asking to define the steps in #2 as shell script "before" Ant script in invoked? I would appreciate if you clarify. – techjourneyman Jul 06 '15 at 18:41
  • @naspras I updated my answer. The idea is to use shell build step for ant also. The advantage of this approach over copying files after ant build is that you can see "workspaces" for each concurrent build in runtime. – Vitalii Elenhaupt Jul 07 '15 at 16:43
2

I added a post-build action in my Jenkins job "jenkinsJob". This action copies the workspace of the job to the parent caller job.

# Store all the children workspace files in the parent job's workspace
mkdir /srv/jenkins/workspace/parentJenkinsJob/${BUILD_NUMBER}
cp -ar * /srv/jenkins/workspace/parentJenkinsJob/${BUILD_NUMBER}

This way multiple workspace folders are created under the parent job, and are accessible from the Jenkins webpage.

techjourneyman
  • 1,701
  • 3
  • 33
  • 53
  • Any idea on how to reference these workspaces in each instance? As a part of the job/workflow (i am using workflow/pipeline), mines involves coping or moving around files from the current workspace (e.g ... /parentJenkinsJob/${BUILD_NUMBER} ) to another location. so i am trying to declare a variable like workspace = pwd() and print this variable so that i can confirm that the variable to set to the path '... /parentJenkinsJob/${BUILD_NUMBER}' .. The groovy syntax doesn't seem to like it. – OK999 Jan 28 '16 at 20:46
  • @naspras, what are parent and children jobs? in your initial question there is no mention of any child/parent relation. There is one job as I can see. Please clarify it. – zubactik Aug 13 '16 at 20:41
  • @all, I also suggest to try `-l` option to `cp` command if you have big workspaces – zubactik Aug 14 '16 at 14:54
1

You can simply add an execute batch command step at the end and make a separate directory and copy the files of the current build into it. You can use a naming convention like Workspace_Build_BuldNumber, so that all workspaces will have a unique number.

LeoN
  • 1,590
  • 1
  • 11
  • 19
0

I think this post can help you. Build a Multi-configuration project (Matrix build).

Community
  • 1
  • 1
Nelson G.
  • 5,145
  • 4
  • 43
  • 54
0

Use a execute windows batch command step at the end. Put this command, so it will move the contents of the workspace to another folder named Workspace_BUILD_NUMER.

mkdir Workspace_%BUILD_NUMBER%
move LoginApp Workspace_%BUILD_NUMBER%/LoginApp 
LeoN
  • 1,590
  • 1
  • 11
  • 19