Pipeline Stage Creation with Gradle Tasks

Hello,

I was wondering if it’s possible for a Jenkins pipeline to auto-create stages for every task that Gradle executes when building a project? It makes it far easier to read via the Jenkins Pipeline UI. Apologies if it’s already been asked but my Google search has turned up zilch.

1 Like

Hi @flaw600,

There is no out-of-the-box solution for this. I was also playing with that idea a bit, but it’s not super easy to do I am afraid. Here are some options:

  1. Listen to the Gradle process and visualize with a “dummy” pipeline: You do only one Gradle execution, as you would normally do, and setup some communication between the running Gradle process and Jenkins. As Jenkins pipelines can be built up dynamically while they are running, I think this should be possible in general. You could probably register a build istener in your build (or inject it using an inti script) and have another process listening on the Jenkins side, that creates stages based on the events from the build. The stages then won’t actually start new build processes, but just visualize the one build process that is running.
  2. Define pipeline and use multiple Gradle invocations: If you always run the same task(s), you could manually define the pipeline corresponding to Gradle’s task graph of your build. (Or you can extract the pipeline from the build - for example by using a listener on TaskGraph.whenReady {}.) Then, in each step of your pipeline, you run a separate Gralde build always executing a different task. Using up-to-date checking and/or the build cache would allow each step to pick up the results from the previous steps. If you also leave the daemon enabled, there is almost no overhead to starting Gradle several times here.
1 Like