GitHub Pages is a neat feature of GitHub that allows you to serve static files by using a special gh-pages
branch in a repository. Having got Jenkins set up to build my jdbc-persist project, I thought it would be neat to set up something to take the Javadoc generated during a build and automatically push it to the gh-pages
branch when the build finishes.
My project uses Maven for building, and I didn't see any way to have the same job that builds the project handle pushing the documentation on a separate branch, so I set up a second job (which I called jdbc-persist-site
) to do that.
The process isn't terribly elegant. The first job uses the Maven site:site
goal to generate both Javadoc and a whole Maven project site. The second project first pulls my gh-pages
branch. It then runs the following batch script (wouldn't be much different as a .sh script):
This basically just grabs the generated site from the other job manually and overwrites the previous version of the files. I actually had to split the three git commands into 3 separate batch file steps in Jenkins because a single script would stop after just 1 git call.
The final step was to push the new commit to gh-pages
so that the updated files would show up. This was a simple matter of selecting the Git Publisher post-build action and telling it to publish to the gh-pages
branch on origin
. I also set up a trigger to run the jdbc-persist-site
job after any successful jdbc-persist
build, ensuring that any changes I make are automatically reflected on the site each time.
I find an approach like this to be far better than the approach of storing generated Javadoc files in the same branch as the source code the way a number of projects I like (Guava and Guice for example) do. Directories containing artifacts like Javadoc that can be derived from the source clutter up the project structure, clutter up commit history with changes to derived files and add to the volume of files that someone checking out the project has to download. I think the ability to do this sort of thing easily speaks well for the ease and power of Git's branching model and for GitHub's awesome features!
1 comments:
Hi,
the code of the batch script seems to have gotten lost - would you mind adding it?
Thanks
- Florian
Post a Comment