Creating Jenkinsfile

We can create the Jenkinsfile and push it to our GitHub repository. Its content is almost the same as the commit pipeline we wrote. The only difference is that the checkout stage becomes redundant because Jenkins has to checkout the code (together with Jenkinsfile) first and then read the pipeline structure (from Jenkinsfile). This is why Jenkins needs to know the repository address before it reads Jenkinsfile.

Let's create a file called Jenkinsfile in the root directory of our project:

pipeline {     agent any     stages {          stage("Compile") {               steps {                    sh "./gradlew compileJava"               }          }          stage("Unit test") {               steps {                    sh "./gradlew test"               }          }     }}

We can now commit the added files and push to the GitHub repository:

$ git add .$ git commit ...

Get Continuous Delivery with Docker and Jenkins now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.