Ganesh Rao B
Ganesh Rao B

Reputation: 501

Changing workspace location in Jenkins using environment variable

I am using Jenkins 'multi job plugin' for ruuning build in jenkins

Currently i have two builds named 'Build_1' and 'Build_2'. These two job combined in two multi job build named 'Parent1' and 'Parent2'.

As shown below

Parent1

  --- build_x

   ---build_y


Parent2

-- build_x

-- build_y

I want to provide different workspace for 'build_x' and 'build_y' when i run through 'Parent1' and 'parent2' build.

The option provided in Jenkins “Use custom workspace" is always fixed for one build but i need to change this location depending upon the trigger from 'parent1' build or 'parent2' build. Is there any option so that on trigger of 'parent1' i set environment variable for workspace location ,so that i can provide different workspace.

Upvotes: 0

Views: 2729

Answers (1)

Daniel Omoto
Daniel Omoto

Reputation: 2481

If you are triggering the build_x and build_y jobs from the parent, then you can pass in the workspace path via a build parameter.

For example:

  1. Create a string parameter called "FolderPathFromParent" in build_x and build_y.
  2. Pass in the string "ParentA" or "ParentB" (depending on the parent) when invoking the child build_x or build_y job as a downstream job.
  3. Set the custom workspace in build_x and build_y to be C:\${FolderPathFromParent}.

When you kick off the parent, it should create a workspace under the C drive called ParentA or ParentB.

Upvotes: 1

Related Questions