Automatically create assembly pipeline for gradle assembly using Jenkinsfile


I am trying to create an assembly pipeline based on Gradle tasks. I looked at the JenkinsFile Pipeline-as-code-demo configuration, but I cannot create a pipeline for Gradle tasks. Please suggest me a possible way so that I can use the Jenkins file to automatically display the assembly pipeline by simply reading the configurations from the Jenkins file.
Thankyou

+8
continuous-integration jenkins gradle
source share
3 answers

If you use Artifactory to resolve build dependencies or to deploy build artifacts, it is recommended that you use Pipeline DSL to build Gradle with Artifactory .

Here is an example taken from the Jenkins pipeline example page:

node { // Get Artifactory server instance, defined in the Artifactory Plugin administration page. def server = Artifactory.server "SERVER_ID" // Create an Artifactory Gradle instance. def rtGradle = Artifactory.newGradleBuild() stage 'Clone sources' git url: 'https://github.com/jfrogdev/project-examples.git' stage 'Artifactory configuration' // Tool name from Jenkins configuration rtGradle.tool = "Gradle-2.4" // Set Artifactory repositories for dependencies resolution and artifacts deployment. rtGradle.deployer repo:'ext-release-local', server: server rtGradle.resolver repo:'remote-repos', server: server stage 'Gradle build' def buildInfo = rtGradle.run rootDir: "gradle-examples/4/gradle-example-ci-server/", buildFile: 'build.gradle', tasks: 'clean artifactoryPublish' stage 'Publish build info' server.publishBuildInfo buildInfo } 

Otherwise, you can simply run the gradle command using the sh or bat pipeline steps.

+15
source share

If your project uses Gradle Wrapper, you can use the following snippet in your Jenkinsfile :

 stage('Gradle Build') { if (isUnix()) { sh './gradlew clean build' } else { bat 'gradlew.bat clean build' } } 

If you go to the sub-dir subdirectory you can use

 stage('Gradle Build') { if (isUnix()) { dir('sub-dir') {sh './gradlew clean build'} } else { dir('sub-dir') {bat 'gradlew.bat clean build'} } } 
+7
source share

In jenkins, you can create a jenkins pipeline using a script that is written in a Jenkins file.

We are writing a script using "steps" and "node" as a building block. These building blocks allow you to specify instructions to be executed as part of the jenkins pipeline.

To complete the gradle build using the JenkinsFile, first check the operating system and invoke the appropriate shell that can perform the gradle task, as shown below:


Jenkinsfile

 stage 'build_Project' node{ if(isUnix()){ sh 'gradle build --info' } else{ bat 'gradle build --info' } } 

Above the code snippet, create a step called build_project and run the gradle build script of the current project.

+5
source share

All Articles