If you want to merge the HTML reports from multiple GoCD Jobs into a single HTML document, you will need a process that runs after all of the relevant Jobs has completed.
The simplest way to accomplish this in GoCD is to add a new Stage that can consume the artifacts generated in the previous Stage:
- Stage 1: Do stuff in multiple Jobs. Generate multiple HTML reports.
- Stage 2: Merge HTML reports from Stage 1.
Another way to accomplish this is to add a Job to the existing Stage where the first Task is to wait for all other Jobs in the Stage to complete:
- Job 1:
- Task 1: Do stuff
- Task 2: Create HTML report
- Job 2:
- Task 1: Do stuff
- Task 2: Create HTML report
- Job 3:
- Task 1: Wait for all other Jobs to complete
- Task 2: Merge HTML reports from all other Jobs
There are some downsides to this approach. Job 3 will often have a much longer runtime than is required to do its work. If you're not using Elastic Agents this means that Job 3 needlessly ties up one of your Agents while waiting for the other Jobs to complete. Depending on the specifics of your GoCD infrastructure configuration, it is even possible for Jobs to be scheduled in such a way that the Pipeline Stage gets blocked. Imagine this as a Template in a setup with just 2 static Agents and 2 Pipelines based on this Template. It is possible, in this scenario, that Pipeline 1 Job 3 gets started on Agent 1 and Pipeline 2 Job 3 gets started on Agent 2 before Job 1/2 from either Pipeline, resulting in both Pipelines being blocked as Job 3 runs forever waiting for the other Jobs to finish and the other Jobs stuck waiting for an Agent on which they can run.
A third way to do it is to add a Task to end of each Job that does the merge work if it is the last Job running for the Stage:
- Job 1:
- Task 1: Do stuff
- Task 2: Generate HTML report
- Task 3: Am I the only unfinished Job? If yes, merge all reports.
- Job 2:
- Task 1: Do stuff
- Task 2: Generate HTML report
- Task 3: Am I the only unfinished Job? If yes, merge all reports.
- ...
- Job N:
- Task 1: Do stuff
- Task 2: Generate HTML report
- Task 3: Am I the only unfinished Job? If yes, merge all reports.
This solution is subject to race conditions, though, because GoCD Jobs do not complete until all Artifacts have been uploaded and Artifacts are not uploaded until after all Tasks complete. This means that it is possible for the last Job to run its "am I the last?" check while the second-to-last Job is still uploading Artifacts. If this happens then the last Job will not recognize that it is the last one and will not run the HTML merge task.
Hope this helps.
Regards,
Jason