Linus Wagner
Linus Wagner

Reputation: 173

Interaction between Gradle and Jenkins in smaller builds

I'm working on a Java application that is build by Gradle and will be integrated into Jenkins.

Ignoring Gradle for a moment, one would setup multiple stages in Jenkins (e.g. Build, Test, Deploy) which are then executed step by step and also shown in the GUI. In Gradle I can use the Java plugin to get a lot of predefined tasks (like build and test). Since build depends on test I basically run a pipeline (the dependency graph) every time I execute build.

What confuses me is how Jenkins and Gradle are playing together in this case. Due to the dependencies in Gradle my Jenkins pipeline shrinks down to (more or less) a single stage and the stages executed in Gradle are hidden in the Jenkins UI.

Is this the "normal" way of doing things? Having all the build logic in Gradle (as it is a build tool after all) and having Jenkins only for the triggers that allow me to automatically execute tasks?

Upvotes: 2

Views: 723

Answers (1)

Sambit
Sambit

Reputation: 8011

In case of Gradle, it is a single command to execute the compile, build goals. It basically performs the build process and finally creates the jar/war file in the end. In case of Jenkins, you need to perform the pipeline processing using the Jenkins stages. The stages may be compile classes, test for executing unit test cases, code analysis using sonar, security check using checkmarx etc. The following snippet will give you an idea of stages in Jenkins pipeline.

stages {
        stage('Compile') {
            steps {
                gradlew('clean', 'classes')
            }
        }
        stage('Unit Tests') {
            steps {
                gradlew('test')
            }
            post {
                always {
                    junit '**/build/test-results/test/TEST-*.xml'
                }
            }
        }
....
.....

To know more details about the flow, refer below the following links.

https://bmuschko.com/blog/jenkins-build-pipeline/

https://docs.gradle.org/current/userguide/jenkins.html

Upvotes: 3

Related Questions