0

I have a jenkins job that do build and deploy the maven project. The job depends on few parameters that I pass to the job. This job also checks out the code from git repository.

I have 4 branches ( dev, test, release and patch) as the source code of the project.

How can I run the same job with different parameters and different source code of the project.

Example : - let say we triggered the job to run by passing param1 and param2 to the job and using the dev branch.

  • taking into consideration that the run from step 1 hasn't completed , how can I trigger the same job by passing param3 and param4 but using test branch this time

I want to do different build from different source branches from the same job in parallel .

Any other suggested design ?

Tareq Assi
  • 149
  • 13

1 Answers1

0

One inherent problem here is that - when you fire another build of the same job, it will overwrite the workspace it is using.

There are two ways of tackling the issue IMO:

  1. Like @bish mentioned in his comment - two separate jobs.
  2. Pass a parameter that will kick off a small script that will checkout the project to a workspace/subdir folder instead of workspace. You can do this in the Add pre-build step -> Execute shell script. Here, you need to ensure that you don't 'wipeout the workspace folder'. (The Jenkins GIT plugin has an option to checkout the project to a subdirectory, but I couldn't figure out how to trigger that conditionally. So, going by a simple manual intervention here.) Next, you can choose to give a list of the branches available as shown in one of my earlier answers

Let me know if this helps.

Community
  • 1
  • 1
Ravindra Mijar
  • 1,282
  • 2
  • 9
  • 17
  • so If I was able to do the build in subdirectory each time I trigger the job to run ,then any team can access the jenkins page , pass their parameters ,select their branch and execute the build , right? – Tareq Assi Dec 23 '15 at 12:01
  • I believe so. Your 1st n 3rd job uses /workspace but your 2nd n 4th job uses /workspace/subdir.. That way.. – Ravindra Mijar Dec 23 '15 at 12:07
  • How many build can be triggered of the same job simultaneously? The idea is that we have a project that should go in the same build cycle from build to deployment and at the same time we have multiple teams need to do the build with different params and different git branch.I'm trying to put the best design so let each team do cycle with their own params,deploy it independently without affecting other teams – Tareq Assi Dec 23 '15 at 12:14
  • With the approach I suggested just 2 builds at a time. I don't understand your plan fully though. With the branches you named I'd imagined this is what your dev ops flow looks like:- dev team works on new unreleased code in Dev branch. Cherry picked commits go to the release branch that are eventually deployed to customers and patch branch will only have custom fixes asked by specific customers. If you don't need to run release and patch jobs frequently I'd suggest to keep them as separate jobs. – Ravindra Mijar Dec 23 '15 at 12:28
  • Thank you , your suggestion to use more than one job seems good – Tareq Assi Dec 27 '15 at 12:40