{"id":1115,"date":"2023-08-30T13:09:31","date_gmt":"2023-08-30T07:39:31","guid":{"rendered":"https:\/\/www.openwriteup.com\/?page_id=1115"},"modified":"2024-04-02T08:47:54","modified_gmt":"2024-04-02T03:17:54","slug":"jenkins-pipeline-project","status":"publish","type":"page","link":"https:\/\/www.openwriteup.com\/?page_id=1115","title":{"rendered":"Jenkins pipeline project"},"content":{"rendered":"<p><span style=\"text-decoration: underline;\"><strong>Youtube Link:<\/strong><\/span> <span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/www.youtube.com\/watch?v=-vKhB3mVrU8&amp;list=PLwO9EbabNLzsaHgP1dUCkdLg2CxZoPXGR&amp;index=9\">Navigation for labs<\/a><\/span><\/p>\n<p>Lab: This lab we will create three projects<\/p>\n<p>-Lab1: Create a basic pipeline project for cowsay utitlity<\/p>\n<ol>\n<li>Click on Dashboard&#8211;&gt; NewItem&#8211;&gt; Project name &#8220;myfirstproj&#8221; &#8211;&gt;Select pipeline&#8211;&gt;Press ok<\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1116\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins10-300x158.png\" alt=\"\" width=\"300\" height=\"158\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins10-300x158.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins10-700x368.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins10-768x403.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins10.png 960w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>2. Under the pipeline script block<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins11.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1117\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins11-300x136.png\" alt=\"\" width=\"300\" height=\"136\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins11-300x136.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins11-700x318.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins11-768x349.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins11.png 951w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>pipeline {\r\n  agent any\r\n   stages {\r\n    stage('Hello') {\r\n      steps {\r\n       sh '\/usr\/games\/cowsay \"hello\" '\r\n     }\r\n   }\r\n }\r\n}<\/pre>\n<p>Click on &#8220;Build now&#8221; and check the build history<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins12.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1119\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins12-300x163.png\" alt=\"\" width=\"300\" height=\"163\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins12-300x163.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins12-700x380.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins12-768x417.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins12.png 995w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Lab2: Scripted pipeline example<\/p>\n<p>Create a new item&#8211;&gt;Name &#8220;scriptedpipeline&#8211;&gt;select pipeline&#8211;&gt; press ok<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins13.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1121\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins13-300x169.png\" alt=\"\" width=\"300\" height=\"169\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins13-300x169.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins13-700x395.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins13-768x433.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins13.png 939w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>In pipeline scripting section<\/p>\n<pre>node {\r\n\/\/ Define the label of the agent where you want to run the pipeline\r\n\/\/label 'mylabel'\r\nstage('Checkout') {\r\n\/\/ Checkout code from the Git repository\r\nsh 'echo checking out'\r\n}\r\nstage('Build') {\r\n\/\/ Build the Java application (replace with your build commands)\r\nsh 'javac -version'\r\n}\r\nstage('Deploy') {\r\n\/\/ Deploy the application (replace with your deployment commands)\r\nsh 'echo \"Deploying the application\"'\r\n}\r\n}<\/pre>\n<p>Click on Build now and check the build history<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins14.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1124\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins14-300x156.png\" alt=\"\" width=\"300\" height=\"156\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins14-300x156.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins14-700x363.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins14-768x398.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins14.png 1022w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Click on build #1, and check the replay option and run, It will execute all the steps<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins15.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1125\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins15-300x236.png\" alt=\"\" width=\"300\" height=\"236\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins15-300x236.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins15.png 678w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Lab3: Declarative pipeline<\/p>\n<p>New Item&#8211;&gt;Name declartivepipeline&#8211;&gt;select pipeline&#8211;&gt;press ok<\/p>\n<p>In pipeline script block<\/p>\n<pre>pipeline {\r\nagent any\r\nstages {\r\n  stage('Checkout') {\r\n    steps {\r\n\/\/ Checkout code from the Git repository\r\n     sh 'echo checking out'\r\n   }\r\n  }\r\nstage('Build') {\r\n  steps {\r\n\/\/ Build the Java application (replace with your build commands)\r\n  sh 'javac -version'\r\n }\r\n}\r\nstage('Deploy') {\r\n  steps {\r\n  \/\/ Deploy the application (replace with your deployment commands)\r\n   sh 'echo \"Deploying the application\"'\r\n   }\r\n  }\r\n }\r\n}<\/pre>\n<p>Click on buildnow&#8211;&gt;Check build history<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins16.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1127\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins16-300x144.png\" alt=\"\" width=\"300\" height=\"144\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins16-300x144.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins16-700x335.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins16-768x368.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins16.png 1015w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Select the build &#8211;&gt;Restart from stage&#8211;&gt;select stage from dropdown&#8211;&gt;Run<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins17.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1128\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins17-300x153.png\" alt=\"\" width=\"300\" height=\"153\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins17-300x153.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins17-700x357.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins17-768x392.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins17.png 1003w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Declartive pipeline provide us , to restart from stage option<\/p>\n<p><strong>Assignment:<\/strong><\/p>\n<ol>\n<li>Go in your git repo &#8220;myrepo&#8221;<\/li>\n<li>Create a &#8220;Jenkinsfile&#8221;<\/li>\n<li>Copy the code from lab 3<\/li>\n<li>checkin the code to github (using git add,commit and push<\/li>\n<li>Create a new pipeline and scripting block dropdown, select &#8220;pipeline with SCM&#8221;<\/li>\n<li>Mention your git repo and save .<\/li>\n<li>Run the build<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Youtube Link: Navigation for labs Lab: This lab we will create three projects -Lab1: Create a basic pipeline project for cowsay utitlity Click on Dashboard&#8211;&gt; NewItem&#8211;&gt; Project name &#8220;myfirstproj&#8221; &#8211;&gt;Select pipeline&#8211;&gt;Press ok 2. Under the pipeline script block pipeline { agent any stages { stage(&#8216;Hello&#8217;) { steps { sh &#8216;\/usr\/games\/cowsay &#8220;hello&#8221; &#8216; } } } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_oct_exclude_from_cache":false,"footnotes":""},"class_list":["post-1115","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/1115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1115"}],"version-history":[{"count":7,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/1115\/revisions"}],"predecessor-version":[{"id":1406,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/1115\/revisions\/1406"}],"wp:attachment":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}