Algirdyz
Algirdyz

Reputation: 617

Include a different job in a job's build steps in Jenkins

I am trying to make this rather unique build flow and I haven't found a plugin or a way to do it with jenkins yet.

There is one job called "JOB A" which is used by itself and creates a standalone installer. Then there is "JOB B" which creates another installer but it needs to include everything built in "JOB A" in addition to some other stuff. Now I could just copy JOB A build steps into JOB B, but I want to actually build JOB A and maybe even use those artifacts later as well.

It cannot be a build trigger cause JOB B needs to continue building after JOB A has finished and I cannot use something like flow because that creates JOB C and only sequences other jobs and I would need to go into A and B to get the artifacts.

Bonus points would be if it checked JOB A source code in git for any changes since its last build when building JOB B and decide if it needs to build it again.

I looked at many plugins and I can't seem to find one that would do this.

I hope my explanation was not confusing. Sorry if it was, I could elaborate.

Upvotes: 1

Views: 1894

Answers (1)

Slav
Slav

Reputation: 27485

If I understand correctly what you want, then what you need is:

For both, JOB A and JOB B, setup Custom Workspace to the same folder on the server (You can even leave JOB A workspace as is, and just point JOB B custome workspace to workspace of JOB A. I am not at my work computer with Jenkins and can't provide screenshots, so I will borrow this great guide for more info on how to setup custom workspace

Then, whenever appropriate, have JOB A execute a build step Trigger/call builds on other projects, namely JOB B. You can even pass it all the same parameters that JOB A had. By default, this will not wait for JOB B to complete. It will kick off JOB B, meanwhile JOB A will finish running, and then JOB B completes whenever it is done.

If needed, you can check-mark Block until triggered projects finish their builds, and then JOB A will wait for JOB B to finish before continuing.

So, the above will:

  • Share workspace, and not do extra checkouts if code didn't change
  • Let JOB A and JOB B exist independently, with it's own artifacts, and each being able to be triggered separately.
  • JOB B will get everything from JOB A through shared workspace and passed parameters.

Upvotes: 3

Related Questions