{"id":2918,"date":"2023-01-15T12:19:34","date_gmt":"2023-01-15T12:19:34","guid":{"rendered":"https:\/\/devclouds.io\/blog\/?p=2918"},"modified":"2023-01-19T09:00:28","modified_gmt":"2023-01-19T09:00:28","slug":"jenkinsfile-jenkins-pipeline-3-4","status":"publish","type":"post","link":"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/","title":{"rendered":"Jenkinsfile &#8211; Jenkins Pipeline 3\/4"},"content":{"rendered":"\n<p>In this article we will learn about Jenkinsfile in Jenkins pipeline. if you want to see our last two lessons.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/devclouds.io\/blog\/run-jenkins-in-docker-container-jenkins-pipeline-1-4\/\">https:\/\/devclouds.io\/blog\/run-jenkins-in-docker-container-jenkins-pipeline-1-4\/<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/devclouds.io\/blog\/create-multibranch-pipeline-with-git-jenkins-pipeline-2-4\/\">https:\/\/devclouds.io\/blog\/create-multibranch-pipeline-with-git-jenkins-pipeline-2-4\/<\/a><\/li>\n<\/ul>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_2-4-1024x446.jpg\" alt=\"dev  branch\" class=\"wp-image-2921\" width=\"768\" height=\"335\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_2-4-1024x446.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_2-4-300x131.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_2-4-768x334.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_2-4.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>let&#8217;s go ahead and create a Jenkinsfile in dev branch. Let&#8217;s go to dev.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_3-3-1024x415.jpg\" alt=\"dev branch new file\" class=\"wp-image-2922\" width=\"768\" height=\"311\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_3-3-1024x415.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_3-3-300x122.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_3-3-768x311.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_3-3.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>And I&#8217;m gonna create a new file.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_4-3-1024x503.jpg\" alt=\"basic jenkins file\" class=\"wp-image-2923\" width=\"768\" height=\"377\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_4-3-1024x503.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_4-3-300x147.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_4-3-768x377.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_4-3.jpg 1085w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>This is the most basic Jenkins file that basically does nothing. But this is the basic syntax we&#8217;re going to go through a Jenkins file syntax in more detail in a later section. But here I&#8217;m gonna explain you the required attributes for Jenkinsfile in jenkins pipeline.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-pipeline-syntax-scripted-vs-declarative\">Pipeline Syntax: Scripted vs. Declarative<\/h2>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_5-4-1024x412.jpg\" alt=\"Pipeline Syntax\" class=\"wp-image-2924\" width=\"768\" height=\"309\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_5-4-1024x412.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_5-4-300x121.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_5-4-768x309.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_5-4.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>So the first thing is that Jenkinsfile can be written as a scripted pipeline or a declarative pipeline. So the scripted pipeline was the first syntax of Jenkins file. What it is it allows to write the whole configuration of the Jenkins file using groovy script.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_6-6-1024x575.jpg\" alt=\"groovy script\" class=\"wp-image-2925\" width=\"768\" height=\"431\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_6-6-1024x575.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_6-6-300x169.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_6-6-768x432.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_6-6.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p> So the only structure that you have there inside of this is groovy scripts. And you can write the whole configuration here in a flexible manner.<\/p>\n\n\n\n<p>So there is no predefined structure there however for people who didn&#8217;t know or doesn&#8217;t know groovy syntax. Or who hasn&#8217;t worked with groovy is little bit difficult to start with.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_7-7-1024x575.jpg\" alt=\"pipeline syntax\" class=\"wp-image-2926\" width=\"768\" height=\"431\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_7-7-1024x575.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_7-7-300x169.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_7-7-768x432.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_7-7.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>That&#8217;s why as a recent addition they actually edit declarative pipeline syntax from Jenkins file. Which is easier to get started with it. Of course it&#8217;s not as powerful as the scripted pipeline. Because here you&#8217;re not limited in. Anyway but it&#8217;s easier to get started with because you have a predefined structure. So this what you see here is basically pre given structure that you have to follow.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_8-6-1024x584.jpg\" alt=\"Required fields of jenkonsfile\" class=\"wp-image-2927\" width=\"768\" height=\"438\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_8-6-1024x584.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_8-6-300x171.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_8-6-768x438.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_8-6.jpg 1241w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In a declarative pipeline you declare that you are writing a pipeline. And &#8220;agent any&#8221; basically means that this build is gonna run on any available Jenkins agent. And agent can be a note it could be executors on that note whatever. This is more relevant when you have a Jenkins cluster so to say with master and slaves where you have Windows nodes and Linux nodes etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Syntax<\/h2>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_9-4.jpg\" alt=\"basic syntax\" class=\"wp-image-2928\" width=\"653\" height=\"564\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_9-4.jpg 871w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_9-4-300x259.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_9-4-768x663.jpg 768w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>But here for the beginning for base we just say &#8220;agent any&#8221;. So we&#8217;ll just run with the next available agent and as I said these two are equivalent to this one here. And they are required attributes you always have to use them. The next required attribute is &#8220;stages&#8221;.<\/p>\n\n\n\n<p>And this is where the whole work actually happens so you have different stages of that pipeline. Inside the stages you define stage name and you can define as many stages as you want. Usually you have something like this so you have a build stage. Maybe you have a test stage and then you have a deploy stage like picture above.<\/p>\n\n\n\n<p>As you see inside the stage you have the steps and here goes the script that actually executes some comment on the Jenkins server or Jenkins agent.<\/p>\n\n\n\n<p>For example if you&#8217;re building a JavaScript application all the NPM install NPM build etc scripts will go here like this.<\/p>\n\n\n\n<p>If you are you know running tests or for Java back-end all the text execution scripts will be here and the deployment script will be here. So right now let&#8217;s just write simple echo comments to kind of test this so here we&#8217;re gonna say building the application. And here we&#8217;re gonna say testing the application and in here we are deploying the application. And this is a Jenkinsfile and this should work.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_10-5.jpg\" alt=\"sample jenkinsfile\" class=\"wp-image-2929\" width=\"570\" height=\"551\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_10-5.jpg 760w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_10-5-300x290.jpg 300w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Now we committed it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Jenkinsfile in Jenkins Pipeline<\/h2>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_11-6-1024x497.jpg\" alt=\"back to our pipeline\" class=\"wp-image-2930\" width=\"768\" height=\"373\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_11-6-1024x497.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_11-6-300x145.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_11-6-768x372.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_11-6.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Let&#8217;s go back to our pipeline and let&#8217;s scan it again.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_12-5-1024x575.jpg\" alt=\"jenkinsfile found\" class=\"wp-image-2931\" width=\"768\" height=\"431\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_12-5-1024x575.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_12-5-300x169.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_12-5-768x432.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_12-5.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>See the logs and you see here it found Jenkinsfile in dev and now it&#8217;s actually executing the Jenkins file.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_13-4-1024x455.jpg\" alt=\"first dev branch\" class=\"wp-image-2932\" width=\"768\" height=\"341\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_13-4-1024x455.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_13-4-300x133.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_13-4-768x341.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_13-4.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>If I go back to my pipeline view. I can see the first branch the dev branch.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_14-5-1024x575.jpg\" alt=\"inside dev branch\" class=\"wp-image-2933\" width=\"768\" height=\"431\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_14-5-1024x575.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_14-5-300x169.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_14-5-768x432.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_14-5.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>let&#8217;s go inside and see the first execution so what happened here the first step that you see is &#8220;check out SCM&#8221;. The second one was built, then test and then deploy. Here you can see the logs and this is what we echoed in each stage &#8220;testing the application&#8221; etc.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_15-3-1024x548.jpg\" alt=\"git url\" class=\"wp-image-2934\" width=\"768\" height=\"411\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_15-3-1024x548.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_15-3-300x161.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_15-3-768x411.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_15-3.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Now the question is where did this come from. This stage is something we didn&#8217;t define before. And it basically checks out the code. So how does this happen this actually comes from my-pipeline that we want <a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Git-Basics-Getting-a-Git-Repository\" target=\"_blank\" rel=\"noreferrer noopener\">git repository<\/a>  URL to be checked out. We basically in UI declaring that we want that checkout stage. <\/p>\n\n\n\n<p>Here inside of that branch configuration you also have some options. Like where you can build the branch manually and see the configuration. <\/p>\n\n\n\n<p>Now what if you want to test some stuff or some changes in a Jenkins file. Let&#8217;s say add one of the steps you want to test some groovy expression. And you are new to groovy so you&#8217;re just learning and you just want to try this out. It will be more effort to you know adjust the Jenkins file and commit it.<\/p>\n\n\n\n<p>You know it has to check out again the changes and rebuild it again etc so there is actually a handy way to do that in Jenkins. So we can test and execute the Jenkins file changes without having to commit each change.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Replay Jenkinsfile in Jenkins pipeline<\/h2>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_16-5-1024x538.jpg\" alt=\"build history\" class=\"wp-image-2935\" width=\"768\" height=\"404\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_16-5-1024x538.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_16-5-300x158.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_16-5-768x403.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_16-5.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The way to do that is go to one of the branches so let&#8217;s say in the dev and here you have the history of the build and if you click inside one of those builds.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_17-5-1024x495.jpg\" alt=\"build replay\" class=\"wp-image-2936\" width=\"768\" height=\"371\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_17-5-1024x495.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_17-5-300x145.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_17-5-768x371.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_17-5.jpg 1330w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Here you have a bunch of options and one of them is replay and what replay does is basically allows you to adjust the last run jenkinsfile and rerun it again.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_18-6-1024x535.jpg\" alt=\"groovy expression\" class=\"wp-image-2937\" width=\"768\" height=\"401\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_18-6-1024x535.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_18-6-300x157.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_18-6-768x401.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_18-6.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>So here let&#8217;s say i want to try some groovy expression. The thing is in this inside the steps you can only write the command, line and comments. So if you want to try it or if you want to execute groovy script then you have to enclose it inside script.<\/p>\n\n\n\n<p>Script will be one of the steps so here you can have &#8220;echo &#8216;building the application&#8230;&#8217; and inside script we can write some groovy expression. So let&#8217;s say let&#8217;s just write something whatever so if this is true then we&#8217;re gonna say &#8220;cool&#8221; if not &#8220;not cool&#8221; and then I&#8217;m gonna echo this and let&#8217;s run.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_19-6-1024x548.jpg\" alt=\"build result\" class=\"wp-image-2938\" width=\"768\" height=\"411\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_19-6-1024x548.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_19-6-300x161.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_19-6-768x411.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_19-6.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>It will build now and here if I open build&#8217;s logs I see &#8220;building the application&#8230;&#8221; and the new message &#8220;cool&#8221;. So when now we tested the changes in the Jenkinsfile without having to actually commit it to the repository.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Restart from stage<\/h2>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_20-5-1024x575.jpg\" alt=\"build's commands\" class=\"wp-image-2939\" width=\"768\" height=\"431\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_20-5-1024x575.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_20-5-300x169.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_20-5-768x432.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_20-5.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Another thing that you can do with the specific build is also so if you click on this triangle you actually see all this commands. You can also do restart from stage.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_21-5-1024x575.jpg\" alt=\"restart from stage\" class=\"wp-image-2940\" width=\"768\" height=\"431\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_21-5-1024x575.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_21-5-300x169.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_21-5-768x432.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_21-5.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>If you click here you see a list a drop down list of all the stages that you have defined. So if one of the stages fails or I don&#8217;t know you need to repeat this stage again. You can actually choose one of the stages without having to repeat all the other.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_22-5-1024x561.jpg\" alt=\"build stage\" class=\"wp-image-2941\" width=\"768\" height=\"421\" srcset=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_22-5-1024x561.jpg 1024w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_22-5-300x164.jpg 300w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_22-5-768x421.jpg 768w, https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/Screenshot_22-5.jpg 1365w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Let&#8217;s actually choose the deploy and if I run in again you see you will skip the previous stages and just do the last one which also could be pretty handy sometimes.<\/p>\n\n\n\n<p>We learn about Jenkinsfile &#8211; jenkins pipeline.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Jenkinsfile &#8211; Jenkins Pipeline | Pipeline Syntax: Scripted vs. Declarative | Basic Syntax | Restart from stage<\/p>\n","protected":false},"author":5,"featured_media":3188,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-2918","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v19.6 (Yoast SEO v19.14) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Jenkinsfile - Jenkins Pipeline 3\/4 - The Official DevClouds Blogs<\/title>\n<meta name=\"description\" content=\"Jenkinsfile - Jenkins Pipeline | Pipeline Syntax: Scripted vs. Declarative | Basic Syntax | Restart from stage\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Jenkinsfile - Jenkins Pipeline 3\/4\" \/>\n<meta property=\"og:description\" content=\"Jenkinsfile - Jenkins Pipeline | Pipeline Syntax: Scripted vs. Declarative | Basic Syntax | Restart from stage\" \/>\n<meta property=\"og:url\" content=\"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/\" \/>\n<meta property=\"og:site_name\" content=\"The Official DevClouds Blogs\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-15T12:19:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-19T09:00:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/demo-y-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"750\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"hammad\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"hammad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/\",\"url\":\"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/\",\"name\":\"Jenkinsfile - Jenkins Pipeline 3\/4 - The Official DevClouds Blogs\",\"isPartOf\":{\"@id\":\"https:\/\/devclouds.io\/blog\/#website\"},\"datePublished\":\"2023-01-15T12:19:34+00:00\",\"dateModified\":\"2023-01-19T09:00:28+00:00\",\"author\":{\"@id\":\"https:\/\/devclouds.io\/blog\/#\/schema\/person\/29fe135874604a656a492f57fb43211d\"},\"description\":\"Jenkinsfile - Jenkins Pipeline | Pipeline Syntax: Scripted vs. Declarative | Basic Syntax | Restart from stage\",\"breadcrumb\":{\"@id\":\"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/devclouds.io\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Jenkinsfile &#8211; Jenkins Pipeline 3\/4\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/devclouds.io\/blog\/#website\",\"url\":\"https:\/\/devclouds.io\/blog\/\",\"name\":\"The Official DevClouds Blogs\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/devclouds.io\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/devclouds.io\/blog\/#\/schema\/person\/29fe135874604a656a492f57fb43211d\",\"name\":\"hammad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/devclouds.io\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/19d1520a5ed46e5c53b8333bc3a9bddb9f28e057d9722fbb8e979edd11e22faf?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/19d1520a5ed46e5c53b8333bc3a9bddb9f28e057d9722fbb8e979edd11e22faf?s=96&d=mm&r=g\",\"caption\":\"hammad\"},\"url\":\"https:\/\/devclouds.io\/blog\/author\/hammad\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Jenkinsfile - Jenkins Pipeline 3\/4 - The Official DevClouds Blogs","description":"Jenkinsfile - Jenkins Pipeline | Pipeline Syntax: Scripted vs. Declarative | Basic Syntax | Restart from stage","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/","og_locale":"en_US","og_type":"article","og_title":"Jenkinsfile - Jenkins Pipeline 3\/4","og_description":"Jenkinsfile - Jenkins Pipeline | Pipeline Syntax: Scripted vs. Declarative | Basic Syntax | Restart from stage","og_url":"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/","og_site_name":"The Official DevClouds Blogs","article_published_time":"2023-01-15T12:19:34+00:00","article_modified_time":"2023-01-19T09:00:28+00:00","og_image":[{"width":750,"height":400,"url":"https:\/\/devclouds.io\/blog\/wp-content\/uploads\/2023\/01\/demo-y-1.png","type":"image\/png"}],"author":"hammad","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hammad","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/","url":"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/","name":"Jenkinsfile - Jenkins Pipeline 3\/4 - The Official DevClouds Blogs","isPartOf":{"@id":"https:\/\/devclouds.io\/blog\/#website"},"datePublished":"2023-01-15T12:19:34+00:00","dateModified":"2023-01-19T09:00:28+00:00","author":{"@id":"https:\/\/devclouds.io\/blog\/#\/schema\/person\/29fe135874604a656a492f57fb43211d"},"description":"Jenkinsfile - Jenkins Pipeline | Pipeline Syntax: Scripted vs. Declarative | Basic Syntax | Restart from stage","breadcrumb":{"@id":"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/devclouds.io\/blog\/jenkinsfile-jenkins-pipeline-3-4\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/devclouds.io\/blog\/"},{"@type":"ListItem","position":2,"name":"Jenkinsfile &#8211; Jenkins Pipeline 3\/4"}]},{"@type":"WebSite","@id":"https:\/\/devclouds.io\/blog\/#website","url":"https:\/\/devclouds.io\/blog\/","name":"The Official DevClouds Blogs","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/devclouds.io\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/devclouds.io\/blog\/#\/schema\/person\/29fe135874604a656a492f57fb43211d","name":"hammad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/devclouds.io\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/19d1520a5ed46e5c53b8333bc3a9bddb9f28e057d9722fbb8e979edd11e22faf?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/19d1520a5ed46e5c53b8333bc3a9bddb9f28e057d9722fbb8e979edd11e22faf?s=96&d=mm&r=g","caption":"hammad"},"url":"https:\/\/devclouds.io\/blog\/author\/hammad\/"}]}},"_links":{"self":[{"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/posts\/2918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/comments?post=2918"}],"version-history":[{"count":5,"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/posts\/2918\/revisions"}],"predecessor-version":[{"id":3218,"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/posts\/2918\/revisions\/3218"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/media\/3188"}],"wp:attachment":[{"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/media?parent=2918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/categories?post=2918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devclouds.io\/blog\/wp-json\/wp\/v2\/tags?post=2918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}