Jenkins | Build and Deploy a Groovy App

Inhaltsverzeichnis [Anzeigen]

Introduction

Using Jenkins as an automation server for your development, you can automate such repeating tasks as testing and deploying your app.

Starting with a sample Groovy App (a simple calculator) with tests, you will learn how to integrate your app in Jenkins and build a pipeline, so that Jenkins runs the desired tasks every time, you change the code.

Prepare the sources

Clone the sample repository from Github.

You should clone the demo repository into you demo account, because you may change some file during this post., and you will not get write permissions for the demo repository.

Also, clone the repository to your local machine to see what our demo app looks like.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git clone https://github.com/jenkins-toolbox/SampleApp_GroovyCalculator
Cloning into 'SampleApp_GroovyCalculator'...
remote: Enumerating objects: 194, done.
remote: Counting objects: 100
remote: Compressing objects: 100
remote: Total 194 (delta 44), reused 137 (delta 23), pack-reused 0
Receiving objects: 100
Resolving deltas: 100
<h4 class="wp-block-heading"><span id="Go_into_the_new_create_folder">Go into the new create folder</span></h4>
<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ cd SampleApp_GroovyCalculator/
$ ls
Jenkinsfile README.md bin build.gradle gradlew src
Makefile SampleCalculator build gradle settings.gradle</pre><h4 class="wp-block-heading"><span id="The_first_task_Jenkins_will_do_in_our_pipeline_build_your_app">The first task, Jenkins will do in our pipeline: build your app</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ./gradlew build</pre><p>Because it’s the first time you start <code>gradlew</code>, the required software will be downloaded:</p><p>First: the current Gradle Version (Gradle is the Build Tool used by Groovy Projects)</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Downloading https://services.gradle.org/distributions/gradle-6.2.1-bin.zip
………10
Welcome to Gradle 6.2.1!
Here are the highlights of this release:
- Dependency checksum and signature verification
- Shareable read-only dependency cache
- Documentation links in deprecation messages
For more details see https://docs.gradle.org/6.2.1/release-notes.html
Starting a Gradle Daemon, 2 stopped Daemons could not be reused, use --status for details</pre><h4 class="wp-block-heading"><span id="After_this_your_app_will_be_tested">After this, your app will be tested</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="ini" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">> Task :test
Calculator02Spec > two plus two should equal four PASSED
Calculator01Spec > add: 2 + 3 PASSED
Calculator01Spec > subtract: 4 - 3 PASSED
Calculator01Spec > multiply: 2 * 3 PASSED
BUILD SUCCESSFUL in 34s
5 actionable tasks: 5 executed</pre><h4 class="wp-block-heading"><span id="Perform_the_build_again">Perform the build again</span></h4><p>No download is required. The build is much quicker.</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ./gradlew build
BUILD SUCCESSFUL in 1s
5 actionable tasks: 5 up-to-date</pre><h4 class="wp-block-heading"><span id="Now_test_our_app">Now, test our app:</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">./gradlew clean test
> Task :test
Calculator02Spec > two plus two should equal four PASSED
Calculator01Spec > add: 2 + 3 PASSED
Calculator01Spec > subtract: 4 - 3 PASSED
Calculator01Spec > multiply: 2 * 3 PASSED
BUILD SUCCESSFUL in 4s
5 actionable tasks: 5 executed</pre><h2 class="wp-block-heading"><span id="Create_a_Jenkins_Pipeline">Create a Jenkins Pipeline</span></h2><p>Start by clicking on the BlueOcean menu item.</p><div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><figure class="wp-block-image size-large"><img decoding="async" width="500" height="775" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20500%20775'%3E%3C/svg%3E" data-src="https://blog.via-internet.de/wp-content/uploads/2020/03/10_blueocean_menuitem-1.png" alt="" class="wp-image-6230 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/10_blueocean_menuitem-1.png 500w, https://via-internet.de/blog/wp-content/uploads/2020/03/10_blueocean_menuitem-1-194x300.png 194w" data-sizes="(max-width: 500px) 100vw, 500px"></figure></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%"><p><strong>Hint:</strong> Blue Ocean is not installed with the default Jenkins installation.</p><p>You have to install the corresponding Plugins.</p><p>Select <code>Manage Jenkins</code> → <code>Manage Plugins</code>.</p><p>Then, select the tab <code>Available</code> and enter in the <code>Filter</code> box: Blue Ocean.</p><p>Install all plugins, that will be listed.</p></div></div><p>Next: Click on the New Pipeline to create your first Pipeline</p><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2040" height="266" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202040%20266'%3E%3C/svg%3E" data-src="https://i2.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/11_create_pipeline_01-1.png?fit=700%2C91&ssl=1" alt="" class="wp-image-6233 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_01-1.png 2040w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_01-1-300x39.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_01-1-1024x134.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_01-1-768x100.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_01-1-1536x200.png 1536w" data-sizes="(max-width: 2040px) 100vw, 2040px"></figure><p>Use the Item GitHub to specify, where our code is stored</p><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2038" height="908" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202038%20908'%3E%3C/svg%3E" data-src="https://i2.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/11_create_pipeline_02-1.png?fit=700%2C312&ssl=1" alt="" class="wp-image-6234 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_02-1.png 2038w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_02-1-300x134.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_02-1-1024x456.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_02-1-768x342.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_02-1-1536x684.png 1536w" data-sizes="auto, (max-width: 2038px) 100vw, 2038px"></figure><p>Next, use your GitHub account.</p><p>Be sure, that you cloned the <a href="https://github.com/jenkins-toolbox/SampleApp_GroovyCalculator">demo repository</a></p><figure class="wp-block-image alignwide size-large"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://blog.via-internet.de/wp-content/uploads/2020/03/11_create_pipeline_03-700x450.png" alt="" class="wp-image-6200 lazy"></figure><p>Next, we select the demo repository <a href="https://github.com/jenkins-toolbox/SampleApp_GroovyCalculator">SampleApp_GroovyCalculator</a></p><figure class="wp-block-image alignwide size-large"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://blog.via-internet.de/wp-content/uploads/2020/03/11_create_pipeline_04-700x708.png" alt="" class="wp-image-6201 lazy"></figure><p>Click on Create Pipeline and after a few seconds, the pipeline is created.</p><figure class="wp-block-image alignwide size-large"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://blog.via-internet.de/wp-content/uploads/2020/03/11_create_pipeline_06-700x732.png" alt="" class="wp-image-6203 lazy"></figure><p>Immediately after creating the pipeline, Jenkins is starting the pipeline and all steps included.</p><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2371" height="524" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202371%20524'%3E%3C/svg%3E" data-src="https://i0.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/22_run_pipeline_1.png?fit=700%2C155&ssl=1" alt="" class="wp-image-6205 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1.png 2371w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1-300x66.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1-1024x226.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1-768x170.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1-1536x339.png 1536w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1-2048x453.png 2048w" data-sizes="auto, (max-width: 2371px) 100vw, 2371px"></figure><p>If everything went well, you see a positive status</p><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2368" height="504" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202368%20504'%3E%3C/svg%3E" data-src="https://i1.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/22_run_pipeline_2.png?fit=700%2C149&ssl=1" alt="" class="wp-image-6206 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2.png 2368w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2-300x64.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2-1024x218.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2-768x163.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2-1536x327.png 1536w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2-2048x436.png 2048w" data-sizes="auto, (max-width: 2368px) 100vw, 2368px"></figure><p>Now, click on the pipeline (e.g. the text <code>master</code> or the status icon) and you will see the pipeline with all steps and their corresponding state.</p><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2364" height="1080" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202364%201080'%3E%3C/svg%3E" data-src="https://i0.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/23_view_pipeline-1.png?fit=700%2C320&ssl=1" alt="" class="wp-image-6208 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1.png 2364w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-300x137.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-1024x468.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-768x351.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-1536x702.png 1536w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-2048x936.png 2048w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-517x235.png 517w" data-sizes="auto, (max-width: 2364px) 100vw, 2364px"></figure><p>If you, want to edit the pipeline, for example to add another step, like on the pencil in the header.</p><figure class="wp-block-image alignwide size-large"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://blog.via-internet.de/wp-content/uploads/2020/03/23_view_pipeline_edit_buttomX-700x31.png" alt="" class="wp-image-6242 lazy"></figure><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2378" height="632" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202378%20632'%3E%3C/svg%3E" data-src="https://i2.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/24_edit_pipeline-1.png?fit=700%2C186&ssl=1" alt="" class="wp-image-6211 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1.png 2378w, https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1-300x80.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1-1024x272.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1-768x204.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1-1536x408.png 1536w, https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1-2048x544.png 2048w" data-sizes="auto, (max-width: 2378px) 100vw, 2378px"></figure><p>Click on <code>Cancel</code> to leave the Pipeline editor.</p><p><strong>Hint</strong>: If you click on <code>Save</code>, all changes are pushed back to the repository and Jenkins starts the Pipeline again.</p><h2 class="wp-block-heading"><span id="Run_the_Pipeline">Run the Pipeline</span></h2><p>If you want to run your pipeline, click on the rerun icon for your pipeline</p><figure class="wp-block-image size-large"><img decoding="async" width="2341" height="138" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202341%20138'%3E%3C/svg%3E" data-src="https://i1.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/31_run_pipeline_rerun.png?fit=700%2C41&ssl=1" alt="" class="wp-image-6212 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun.png 2341w, https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun-300x18.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun-1024x60.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun-768x45.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun-1536x91.png 1536w, https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun-2048x121.png 2048w" data-sizes="auto, (max-width: 2341px) 100vw, 2341px"></figure>
gitclonehttps://github.com/jenkinstoolbox/SampleAppGroovyCalculatorCloningintoSampleAppGroovyCalculator...remote:Enumeratingobjects:194,done.remote:Countingobjects:100remote:Compressingobjects:100remote:Total194(delta44),reused137(delta23),packreused0Receivingobjects:100Resolvingdeltas:100<h4class="wpblockheading"><spanid="Gointothenewcreatefolder">Gointothenewcreatefolder</span></h4><preclass="EnlighterJSRAW"dataenlighterlanguage="shell"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> cd SampleApp_GroovyCalculator/ lsJenkinsfileREADME.mdbinbuild.gradlegradlewsrcMakefileSampleCalculatorbuildgradlesettings.gradle</pre><h4class="wpblockheading"><spanid="ThefirsttaskJenkinswilldoinourpipelinebuildyourapp">Thefirsttask,Jenkinswilldoinourpipeline:buildyourapp</span></h4><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> ./gradlew build</pre><p>Because it’s the first time you start <code>gradlew</code>, the required software will be downloaded:</p><p>First: the current Gradle Version (Gradle is the Build Tool used by Groovy Projects)</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Downloading https://services.gradle.org/distributions/gradle-6.2.1-bin.zip ………10 Welcome to Gradle 6.2.1! Here are the highlights of this release: - Dependency checksum and signature verification - Shareable read-only dependency cache - Documentation links in deprecation messages For more details see https://docs.gradle.org/6.2.1/release-notes.html Starting a Gradle Daemon, 2 stopped Daemons could not be reused, use --status for details</pre><h4 class="wp-block-heading"><span id="After_this_your_app_will_be_tested">After this, your app will be tested</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="ini" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">> Task :test Calculator02Spec > two plus two should equal four PASSED Calculator01Spec > add: 2 + 3 PASSED Calculator01Spec > subtract: 4 - 3 PASSED Calculator01Spec > multiply: 2 * 3 PASSED BUILD SUCCESSFUL in 34s 5 actionable tasks: 5 executed</pre><h4 class="wp-block-heading"><span id="Perform_the_build_again">Perform the build again</span></h4><p>No download is required. The build is much quicker.</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ./gradlew build BUILD SUCCESSFUL in 1s 5 actionable tasks: 5 up-to-date</pre><h4 class="wp-block-heading"><span id="Now_test_our_app">Now, test our app:</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">./gradlew clean test > Task :test Calculator02Spec > two plus two should equal four PASSED Calculator01Spec > add: 2 + 3 PASSED Calculator01Spec > subtract: 4 - 3 PASSED Calculator01Spec > multiply: 2 * 3 PASSED BUILD SUCCESSFUL in 4s 5 actionable tasks: 5 executed</pre><h2 class="wp-block-heading"><span id="Create_a_Jenkins_Pipeline">Create a Jenkins Pipeline</span></h2><p>Start by clicking on the BlueOcean menu item.</p><div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><figure class="wp-block-image size-large"><img decoding="async" width="500" height="775" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20500%20775'%3E%3C/svg%3E" data-src="https://blog.via-internet.de/wp-content/uploads/2020/03/10_blueocean_menuitem-1.png" alt="" class="wp-image-6230 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/10_blueocean_menuitem-1.png 500w, https://via-internet.de/blog/wp-content/uploads/2020/03/10_blueocean_menuitem-1-194x300.png 194w" data-sizes="(max-width: 500px) 100vw, 500px"></figure></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%"><p><strong>Hint:</strong> Blue Ocean is not installed with the default Jenkins installation.</p><p>You have to install the corresponding Plugins.</p><p>Select <code>Manage Jenkins</code> → <code>Manage Plugins</code>.</p><p>Then, select the tab <code>Available</code> and enter in the <code>Filter</code> box: Blue Ocean.</p><p>Install all plugins, that will be listed.</p></div></div><p>Next: Click on the New Pipeline to create your first Pipeline</p><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2040" height="266" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202040%20266'%3E%3C/svg%3E" data-src="https://i2.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/11_create_pipeline_01-1.png?fit=700%2C91&ssl=1" alt="" class="wp-image-6233 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_01-1.png 2040w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_01-1-300x39.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_01-1-1024x134.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_01-1-768x100.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_01-1-1536x200.png 1536w" data-sizes="(max-width: 2040px) 100vw, 2040px"></figure><p>Use the Item GitHub to specify, where our code is stored</p><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2038" height="908" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202038%20908'%3E%3C/svg%3E" data-src="https://i2.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/11_create_pipeline_02-1.png?fit=700%2C312&ssl=1" alt="" class="wp-image-6234 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_02-1.png 2038w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_02-1-300x134.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_02-1-1024x456.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_02-1-768x342.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/11_create_pipeline_02-1-1536x684.png 1536w" data-sizes="auto, (max-width: 2038px) 100vw, 2038px"></figure><p>Next, use your GitHub account.</p><p>Be sure, that you cloned the <a href="https://github.com/jenkins-toolbox/SampleApp_GroovyCalculator">demo repository</a></p><figure class="wp-block-image alignwide size-large"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://blog.via-internet.de/wp-content/uploads/2020/03/11_create_pipeline_03-700x450.png" alt="" class="wp-image-6200 lazy"></figure><p>Next, we select the demo repository <a href="https://github.com/jenkins-toolbox/SampleApp_GroovyCalculator">SampleApp_GroovyCalculator</a></p><figure class="wp-block-image alignwide size-large"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://blog.via-internet.de/wp-content/uploads/2020/03/11_create_pipeline_04-700x708.png" alt="" class="wp-image-6201 lazy"></figure><p>Click on Create Pipeline and after a few seconds, the pipeline is created.</p><figure class="wp-block-image alignwide size-large"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://blog.via-internet.de/wp-content/uploads/2020/03/11_create_pipeline_06-700x732.png" alt="" class="wp-image-6203 lazy"></figure><p>Immediately after creating the pipeline, Jenkins is starting the pipeline and all steps included.</p><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2371" height="524" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202371%20524'%3E%3C/svg%3E" data-src="https://i0.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/22_run_pipeline_1.png?fit=700%2C155&ssl=1" alt="" class="wp-image-6205 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1.png 2371w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1-300x66.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1-1024x226.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1-768x170.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1-1536x339.png 1536w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_1-2048x453.png 2048w" data-sizes="auto, (max-width: 2371px) 100vw, 2371px"></figure><p>If everything went well, you see a positive status</p><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2368" height="504" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202368%20504'%3E%3C/svg%3E" data-src="https://i1.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/22_run_pipeline_2.png?fit=700%2C149&ssl=1" alt="" class="wp-image-6206 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2.png 2368w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2-300x64.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2-1024x218.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2-768x163.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2-1536x327.png 1536w, https://via-internet.de/blog/wp-content/uploads/2020/03/22_run_pipeline_2-2048x436.png 2048w" data-sizes="auto, (max-width: 2368px) 100vw, 2368px"></figure><p>Now, click on the pipeline (e.g. the text <code>master</code> or the status icon) and you will see the pipeline with all steps and their corresponding state.</p><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2364" height="1080" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202364%201080'%3E%3C/svg%3E" data-src="https://i0.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/23_view_pipeline-1.png?fit=700%2C320&ssl=1" alt="" class="wp-image-6208 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1.png 2364w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-300x137.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-1024x468.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-768x351.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-1536x702.png 1536w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-2048x936.png 2048w, https://via-internet.de/blog/wp-content/uploads/2020/03/23_view_pipeline-1-517x235.png 517w" data-sizes="auto, (max-width: 2364px) 100vw, 2364px"></figure><p>If you, want to edit the pipeline, for example to add another step, like on the pencil in the header.</p><figure class="wp-block-image alignwide size-large"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://blog.via-internet.de/wp-content/uploads/2020/03/23_view_pipeline_edit_buttomX-700x31.png" alt="" class="wp-image-6242 lazy"></figure><figure class="wp-block-image alignwide size-large"><img decoding="async" width="2378" height="632" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202378%20632'%3E%3C/svg%3E" data-src="https://i2.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/24_edit_pipeline-1.png?fit=700%2C186&ssl=1" alt="" class="wp-image-6211 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1.png 2378w, https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1-300x80.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1-1024x272.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1-768x204.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1-1536x408.png 1536w, https://via-internet.de/blog/wp-content/uploads/2020/03/24_edit_pipeline-1-2048x544.png 2048w" data-sizes="auto, (max-width: 2378px) 100vw, 2378px"></figure><p>Click on <code>Cancel</code> to leave the Pipeline editor.</p><p><strong>Hint</strong>: If you click on <code>Save</code>, all changes are pushed back to the repository and Jenkins starts the Pipeline again.</p><h2 class="wp-block-heading"><span id="Run_the_Pipeline">Run the Pipeline</span></h2><p>If you want to run your pipeline, click on the rerun icon for your pipeline</p><figure class="wp-block-image size-large"><img decoding="async" width="2341" height="138" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%202341%20138'%3E%3C/svg%3E" data-src="https://i1.wp.com/blog.via-internet.de/wp-content/uploads/2020/03/31_run_pipeline_rerun.png?fit=700%2C41&ssl=1" alt="" class="wp-image-6212 lazy" data-srcset="https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun.png 2341w, https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun-300x18.png 300w, https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun-1024x60.png 1024w, https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun-768x45.png 768w, https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun-1536x91.png 1536w, https://via-internet.de/blog/wp-content/uploads/2020/03/31_run_pipeline_rerun-2048x121.png 2048w" data-sizes="auto, (max-width: 2341px) 100vw, 2341px"></figure>
$ git clone https://github.com/jenkins-toolbox/SampleApp_GroovyCalculator
Cloning into 'SampleApp_GroovyCalculator'...
remote: Enumerating objects: 194, done.
remote: Counting objects: 100
remote: Compressing objects: 100
remote: Total 194 (delta 44), reused 137 (delta 23), pack-reused 0
Receiving objects: 100
Resolving deltas: 100



Go into the new create folder

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ cd SampleApp_GroovyCalculator/
$ ls
Jenkinsfile README.md bin build.gradle gradlew src
Makefile SampleCalculator build gradle settings.gradle
$ cd SampleApp_GroovyCalculator/ $ ls Jenkinsfile README.md bin build.gradle gradlew src Makefile SampleCalculator build gradle settings.gradle
$ cd SampleApp_GroovyCalculator/
$ ls
Jenkinsfile      README.md        bin              build.gradle     gradlew          src
Makefile         SampleCalculator build            gradle           settings.gradle

The first task, Jenkins will do in our pipeline: build your app

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ ./gradlew build
$ ./gradlew build
$ ./gradlew build

Because it’s the first time you start gradlew, the required software will be downloaded:

First: the current Gradle Version (Gradle is the Build Tool used by Groovy Projects)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Downloading https://services.gradle.org/distributions/gradle-6.2.1-bin.zip
………10
Welcome to Gradle 6.2.1!
Here are the highlights of this release:
- Dependency checksum and signature verification
- Shareable read-only dependency cache
- Documentation links in deprecation messages
For more details see https://docs.gradle.org/6.2.1/release-notes.html
Starting a Gradle Daemon, 2 stopped Daemons could not be reused, use --status for details
Downloading https://services.gradle.org/distributions/gradle-6.2.1-bin.zip ………10 Welcome to Gradle 6.2.1! Here are the highlights of this release: - Dependency checksum and signature verification - Shareable read-only dependency cache - Documentation links in deprecation messages For more details see https://docs.gradle.org/6.2.1/release-notes.html Starting a Gradle Daemon, 2 stopped Daemons could not be reused, use --status for details
Downloading https://services.gradle.org/distributions/gradle-6.2.1-bin.zip
………10

Welcome to Gradle 6.2.1!

Here are the highlights of this release:
 - Dependency checksum and signature verification
 - Shareable read-only dependency cache
 - Documentation links in deprecation messages

For more details see https://docs.gradle.org/6.2.1/release-notes.html

Starting a Gradle Daemon, 2 stopped Daemons could not be reused, use --status for details

After this, your app will be tested

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
> Task :test
Calculator02Spec > two plus two should equal four PASSED
Calculator01Spec > add: 2 + 3 PASSED
Calculator01Spec > subtract: 4 - 3 PASSED
Calculator01Spec > multiply: 2 * 3 PASSED
BUILD SUCCESSFUL in 34s
5 actionable tasks: 5 executed
> Task :test Calculator02Spec > two plus two should equal four PASSED Calculator01Spec > add: 2 + 3 PASSED Calculator01Spec > subtract: 4 - 3 PASSED Calculator01Spec > multiply: 2 * 3 PASSED BUILD SUCCESSFUL in 34s 5 actionable tasks: 5 executed
> Task :test

Calculator02Spec > two plus two should equal four PASSED

Calculator01Spec > add: 2 + 3 PASSED

Calculator01Spec > subtract: 4 - 3 PASSED

Calculator01Spec > multiply: 2 * 3 PASSED

BUILD SUCCESSFUL in 34s
5 actionable tasks: 5 executed

Perform the build again

No download is required. The build is much quicker.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ ./gradlew build
BUILD SUCCESSFUL in 1s
5 actionable tasks: 5 up-to-date
$ ./gradlew build BUILD SUCCESSFUL in 1s 5 actionable tasks: 5 up-to-date
$ ./gradlew build

BUILD SUCCESSFUL in 1s
5 actionable tasks: 5 up-to-date

Now, test our app:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
./gradlew clean test
> Task :test
Calculator02Spec > two plus two should equal four PASSED
Calculator01Spec > add: 2 + 3 PASSED
Calculator01Spec > subtract: 4 - 3 PASSED
Calculator01Spec > multiply: 2 * 3 PASSED
BUILD SUCCESSFUL in 4s
5 actionable tasks: 5 executed
./gradlew clean test > Task :test Calculator02Spec > two plus two should equal four PASSED Calculator01Spec > add: 2 + 3 PASSED Calculator01Spec > subtract: 4 - 3 PASSED Calculator01Spec > multiply: 2 * 3 PASSED BUILD SUCCESSFUL in 4s 5 actionable tasks: 5 executed
./gradlew clean test

> Task :test

Calculator02Spec > two plus two should equal four PASSED

Calculator01Spec > add: 2 + 3 PASSED

Calculator01Spec > subtract: 4 - 3 PASSED

Calculator01Spec > multiply: 2 * 3 PASSED

BUILD SUCCESSFUL in 4s
5 actionable tasks: 5 executed

Create a Jenkins Pipeline

Start by clicking on the BlueOcean menu item.

Hint: Blue Ocean is not installed with the default Jenkins installation.

You have to install the corresponding Plugins.

Select Manage JenkinsManage Plugins.

Then, select the tab Available and enter in the Filter box: Blue Ocean.

Install all plugins, that will be listed.

Next: Click on the New Pipeline to create your first Pipeline

Use the Item GitHub to specify, where our code is stored

Next, use your GitHub account.

Be sure, that you cloned the demo repository

Next, we select the demo repository SampleApp_GroovyCalculator

Click on Create Pipeline and after a few seconds, the pipeline is created.

Immediately after creating the pipeline, Jenkins is starting the pipeline and all steps included.

If everything went well, you see a positive status

Now, click on the pipeline (e.g. the text master or the status icon) and you will see the pipeline with all steps and their corresponding state.

If you, want to edit the pipeline, for example to add another step, like on the pencil in the header.

Click on Cancel to leave the Pipeline editor.

Hint: If you click on Save, all changes are pushed back to the repository and Jenkins starts the Pipeline again.

Run the Pipeline

If you want to run your pipeline, click on the rerun icon for your pipeline