Tarek
Tarek

Reputation: 3160

How to create a job hierarchy with Jenkins?

we have a series of shell scripts at work that I am trying to improve upon by using Jenkins (in order to have much more control and to allow developers unfamiliar with shell scripts to understand and change the process if needed).

I have had no problems with scripts that involved basically checking out the project with SVN, building it with Maven and deploying the war to our container.

But now I am trying to create a Jenkins job to package Linux, Linux x86_64 and Windows installers for our clients. The script does the following:

  1. checks out the project (SVN);
  2. builds the main project with the test profile (Maven);
  3. copies the war to a Samba Share (smbclient);
  4. rebuilds the project with the production profile;
  5. updates versioned (SVN) folders within the Linux, Linux64 and Windows folders;
  6. copy the war in the linux folder;
  7. creates a tarball using the Linux folder;
  8. copy the war in the Linux64 folder;
  9. creates a tarball using the Linux64 folder;
  10. copies the war into the Windows folder;
  11. creates a Windows executable with InnoSetup running on Wine;
  12. copies the packages to the Samba Share.

This script is way too complicated, and there are many redundancies between the Linux, Linux64 and Windows folders. I've imagined an improved process, where I'd use the following folder structure:

libs
|-- unversioned-folder
|-- linux
|   `-- specific linux files
|-- linux64
|   `-- specific linux x86_64 files
`-- windows
    `-- specific windows files

workspace
|-- main-project
`-- versioned-folder
    |-- versioned-subfolder1
    |-- versioned-subfolder2
    |-- unversioned-folder  (copied from libs)
    |   `-- main-project.war (built with Maven from the main-project)
    `-- Linux or Linux64 or Windows specific folder (overwritten after each packaging)

That way, versioned folders are not repeated and I can package the Linux, Linux64 and Windows installers without redundancies and just overwriting the specific files for each.

I've been experimenting with Jenkins, and am using the Publish Over CIFS plugin for the first part of the script. But if I continue using the same job, I've realized it would both be too complicated and that most of the steps would happen in the post-build part.

The ideal way would be to break the job into smaller jobs, much like one would call functions in a shell script. Now I'm studying the Multijob plugin.

I'd like to know if it's possible to have this hierarchy in Jenkins, sharing the parent job's workspace:

Installation job

  1. checkout main project
  2. sub-job: Create test project
    1. build the main project with test profile
    2. copy the war file to a Windows Share
  3. sub-job: Create production project
    1. rebuild the main project with production profile
  4. sub-job: create packages
    1. checkout versioned folders;
    2. copy unversioned folder into the versioned folder;
    3. copy the main project war file into the unversioned folder;
    4. sub-job: package linux installer
      1. copy unversioned linux specific files into the versioned folder;
      2. create a tarball (packaging).
    5. sub-job: package linux x86_64 installer
      1. copy unversioned linux64 specific files;
      2. create a tarball (packaging).
    6. sub-job: package windows installer
      1. copy unversioned windows specific files;
      2. create an executable installer using InnoSetup (probably shell script with wine).
    7. send packages to Windows Share.

In case the parent job's workspace cannot be shared among sub-jobs, how could I achieve the same result as the shell script with Jenkins?

Upvotes: 3

Views: 3216

Answers (1)

Destroyica
Destroyica

Reputation: 4267

Use the Clone Workspace plug-in to share your .war / files across jobs:
https://wiki.jenkins-ci.org/display/JENKINS/Clone+Workspace+SCM+Plugin

And use Build Flow to parallelize OS specific sub-jobs:
https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin

Upvotes: 1

Related Questions