0

I have got a chain of jobs, which builds an application. Let's call this chain 1.

I want to include this steps also in the middle of an other chain of jobs (chain 2). If I do that, the last job of chain 1 gets a following job, which I have no control overt not to be build, when I only want to build the original chain 1.

   J1  
   |  
J2 J2  
|  |  
J3 J3  
   |
   J4

I don't want to duplicate J2 and J3, but this is not possible, isn't it?

andreas
  • 1,483
  • 1
  • 15
  • 36

3 Answers3

1

I found a solution inspired by an other answer here on stackoverflow.com: Jenkins - conditions between build steps

In a predecessor job I write a temporary file with a windows batch job:

echo call_conditional_next_job = true > c:\temp\build.properties

To read out the properties file and set some environment variables I use the "Jenkins Environment Injector Plug-in". Several jobs later down in the chain I added following windows batch job:

Several jobs down in the chain I use the "Jenkins Environment Injector Plug-in" to read out the properties file. Then in the same job I use following windows batch job to conditional start the "conditional-next-job" jenkins job:

IF "%call_conditional_next_job%"=="true" wget http://localhost:8080/job/conditional-next-job/build?delay=0sec  
IF NOT "%call_conditional_next_job%"=="true" echo "do not call conditional-next-job."

If one finds an more elegant way to send an environment variable down the stream... It would be nice to know.

Community
  • 1
  • 1
andreas
  • 1,483
  • 1
  • 15
  • 36
0

Not as you describe.

However, the pain is not that bad. From the "New Job" dialog, you can copy another preexisting job, so all you would have to do is copy J2 and J3, and change the 'build after' tag for J3. There are plugins to filter jobs if you don't want both sets of jobs to appear on the same build page.

Kane
  • 4,047
  • 2
  • 24
  • 33
  • That's exactly what I want to avoid. Our jobs are allready quite complex and have a lot of dependencies. To duplicate them even for this scenario will bring us in a maintainance hell... – andreas Oct 26 '11 at 20:45
  • I see. Could you provide a use case for this? While I understand you wanting to avoid maintenance hell (who doesn't?), it might be easier to understand if I see the larger issue of why you want to be able to execute a partial chain of actions. – Kane Oct 26 '11 at 21:00
  • The compile output of the short chain can stand for it's own or be an prerequisite for an job later down in the long chain. As this would be a complete copy, I want to avoid it. – andreas Oct 26 '11 at 21:13
0

If J1 and J3 share a common, fingerprinted file, there might be a way to make this work.

  1. Modify the J1 job to call J2 at the end of the build (which in turn, calls J3).
  2. Modify the J1 job to have a promotion process that triggers on the successful downstream completion of J3. As an action of the promotion process, add a Trigger build on another project and specify J4 as the project to build.
Jason Swager
  • 6,421
  • 6
  • 41
  • 56