<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: gurunadh</title>
    <description>The latest articles on DEV Community by gurunadh (@gurunadh234).</description>
    <link>https://dev.to/gurunadh234</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1848644%2F328ab6b1-20e7-46b7-8fff-1aaa08c563b6.png</url>
      <title>DEV Community: gurunadh</title>
      <link>https://dev.to/gurunadh234</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gurunadh234"/>
    <language>en</language>
    <item>
      <title>Kubernetes</title>
      <dc:creator>gurunadh</dc:creator>
      <pubDate>Sat, 10 Aug 2024 19:34:30 +0000</pubDate>
      <link>https://dev.to/gurunadh234/kubernetes-jj7</link>
      <guid>https://dev.to/gurunadh234/kubernetes-jj7</guid>
      <description>&lt;p&gt;Kubernetes is an open-source container orchestrator. To know about container orchestration and orchestrators visit &lt;a href="https://dev.to/gurunadh234/container-orchestration-367"&gt;Container Orchestration&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Kubernetes is sometimes shortened to k8s, as there are 8 characters between K and S.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  History
&lt;/h2&gt;
&lt;/blockquote&gt;

&lt;p&gt;Kubernetes originated from a Greek word &lt;strong&gt;κυβερνήτης (kubernḗtēs)&lt;/strong&gt;, meaning 'helmsman' or 'ship pilot'. As the name suggests, Kubernetes acts as the pilot on the ship of containers.&lt;/p&gt;

&lt;p&gt;Kubernetes was originally developed by Google as part of their Borg System (Cluster Manager) and was later donated it to Cloud Native Computing Foundation (CNCF).&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Automated Rollouts and Rollbacks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kubernetes progressively rolls out changes to your application or its configuration, while monitoring application health to ensure it doesn't kill all your instances at the same time. If something goes wrong, Kubernetes will roll back the change for you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Service Discovery and Load Balancing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Storage Orchestration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Automatically mount the storage system of your choice, whether from local storage, a public cloud provider, or a network storage system such as iSCSI or NFS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Self Healing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Restarts containers that fail, replaces and reschedules containers when nodes die, kills containers that don't respond to user-defined health check, and doesn't advertise them to clients until they are ready to serve.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secret and Configuration Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Deploy and update Secrets and application configuration without rebuilding your image and without exposing Secrets in your stack configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automatic Bin Packing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Automatically places containers based on their resource requirements and other constraints, while not sacrificing availability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Batch Execution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In addition to services, Kubernetes can manage your batch and CI workloads, replacing containers that fail, if desired.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Horizontal Scaling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Scale your application up and down with a simple command, with a UI, or automatically based on CPU usage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IPV4/IPV6 dual stack&lt;/strong&gt;&lt;br&gt;
Supports both IPv4 and IPv6 addresses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Portability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kubernetes can be deployed in many environments such as local, remote VMs, in public/private/hybrid clouds.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Architecture
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;Kubernetes' architecture consists of&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Control Plane Node &lt;/li&gt;
&lt;li&gt;Worker Node&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F844jeeylosa7bz8phe7n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F844jeeylosa7bz8phe7n.png" alt="Kubernetes-architecture" width="800" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  Worker Node &amp;amp; Components
&lt;/h2&gt;
&lt;/blockquote&gt;

&lt;p&gt;Worker nodes provide a runtime environment for applications deployed in the cluster. Applications will be deployed only in the worker node, not in control plane node.&lt;/p&gt;

&lt;p&gt;In multi-worker cluster traffic, between client and application deployed in Pods is handled directly by the worker node and is not routed through the control plane node. Each node can have multiple Pods in it.&lt;/p&gt;

&lt;p&gt;Worker nodes must have three components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Container Runtime&lt;/strong&gt;&lt;br&gt;
Although Kubernetes is a container orchestrator, it cannot run the containers directly. In order to manage container's lifecycle, Kubernetes needs a container runtime on both the worker node and control plane node.&lt;/p&gt;

&lt;p&gt;Popular runtime tools in Kubernetes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CRI-O&lt;/strong&gt; - A lightweight container runtime for k8s. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;containerd&lt;/strong&gt; - A simple robust and portable container runtime. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker engine&lt;/strong&gt; - Earlier it was the default runtime but deprecated in kubernetes version 1.20&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kubelet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kubelet takes a set of PodSpec (simple yaml object that describes pod specifications) primarily from API server and is responsible to create the pod, assigns resource to the container from the node and manage containers lifecycle in the pod by interacting with the container runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kube-proxy&lt;/strong&gt;&lt;br&gt;
Kube proxy handles communication to and from pods that are part of a service within the cluster.&lt;/p&gt;

&lt;p&gt;It forwards the requests between pods in an efficient manner and with low overhead.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  Control Plane Node &amp;amp; Components
&lt;/h2&gt;
&lt;/blockquote&gt;

&lt;p&gt;The control plane's components make global decisions about the cluster as well as detecting and responding to cluster events like starting up a new pod when Deployment replica's field is unsatisfied.&lt;/p&gt;

&lt;p&gt;There are 4 main components in control plane&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API Server&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;API Server acts as a cluster gateway also acts as gatekeeper for authentication of the Kubernetes. It is a critical component in Kubernetes that manages all the communication in the cluster.&lt;/p&gt;

&lt;p&gt;We can run multiple api-server to balance the traffic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scheduler&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When there is a request from client to schedule a pod, API server sends request to &lt;strong&gt;Scheduler&lt;/strong&gt; to start the pod in one of the worker nodes. Scheduler is smart enough to choose a node that meets the pod requirements like ram, cpu, and least busy node with the required specification will be chosen to create the pod.&lt;/p&gt;

&lt;p&gt;Scheduler just decides on which node a pod should be scheduled, while kubelet is responsible to create the pod.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;etcd&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is the cluster brain, a consistent and highly-available key value store used as Kubernetes' backing store for all cluster data and not applications' data deployed in the cluster.&lt;/p&gt;

&lt;p&gt;Every change in the cluster, when a new Pod gets scheduled, when a Pod dies, application deployment state, cluster health — all these changes will be stored as key-value store in etcd.&lt;/p&gt;

&lt;p&gt;New data is written to the data store only by appending, data is never replaced, but obsolete data is deleted periodically to minimize size of the data store.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Controller Manager&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Controller manager detects the cluster state change, when a pod dies in any node, the controller manager creates a new pod object and sends a request to the API server to create a pod with a desired state which will then send a request to the scheduler.&lt;/p&gt;

&lt;p&gt;Kubernetes doesn't guarantee that the replacement for an existing pod will be scheduled to the same node as the old pod that was being replaced.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>kubernetes</category>
      <category>containers</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Container Orchestration</title>
      <dc:creator>gurunadh</dc:creator>
      <pubDate>Sat, 10 Aug 2024 18:04:21 +0000</pubDate>
      <link>https://dev.to/gurunadh234/container-orchestration-367</link>
      <guid>https://dev.to/gurunadh234/container-orchestration-367</guid>
      <description>&lt;p&gt;Before learning about Container Orchestration lets learn about Containers.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Containers
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;Containers are application centric method to deliver high performing and scalable application on any infrastructure of our choice. It is best suited to deliver microservices by providing portable, isolated virtual environments.&lt;/p&gt;

&lt;p&gt;Containers encapsulate microservices and their dependencies but do not run them directly. Containers run container images.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Container Image&lt;/strong&gt; bundles the application along with its runtime, libraries and dependencies, and it represents the source of a container deployed to offer an isolated executable environment to run the application.&lt;/p&gt;

&lt;p&gt;Containers can be deployed from a specific image on many platforms such as virtual machines, public cloud.&lt;/p&gt;




&lt;p&gt;Now lets dive into Container Orchestration.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Container Orchestration
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;In development environments, using the container on a single host for application development and testing can be practical, but when moving to QA and Prod environments requires several critical criteria.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Efficient resource utilization&lt;/li&gt;
&lt;li&gt;On-demand scalability&lt;/li&gt;
&lt;li&gt;Fault tolerance&lt;/li&gt;
&lt;li&gt;Ability to perform updated and rollbacks without downtime&lt;/li&gt;
&lt;li&gt;Auto discovery for seamless inter-service communication&lt;/li&gt;
&lt;li&gt;Self-healing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Container Orchestration&lt;/strong&gt; is the process of combining multiple systems into clusters, automating the deployment and management of containers at scale and the ability to monitor the container health and automatically replaces or restarts the failed containers while fulfilling the above-mentioned requirements.&lt;/p&gt;

&lt;p&gt;These clusters leverage the benefits of distributed systems, including enhanced performance, cost-effectiveness, reliability, balanced workload distribution and lower latency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Container Orchestrators&lt;/strong&gt; are the tools that facilitates container orchestration and provides necessary functionalities to perform the above mentioned requirements.&lt;/p&gt;

&lt;p&gt;Popular Container Orchestrators are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kubernetes&lt;/strong&gt; is an open source orchestration tool, originally developed by Google, later donated to the Cloud Native Computing Foundation (CNCF).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker Swarm&lt;/strong&gt; is a container orchestrator provided by Docker and is part of docker engine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amazon ECS&lt;/strong&gt; is a fully managed container orchestration service by AWS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Azure Container Instances (ACI)&lt;/strong&gt; is a basic container orchestration tool provided by Microsoft Azure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nomad&lt;/strong&gt; is a container and workload orchestrator provided by HashiCorp.&lt;/p&gt;

&lt;p&gt;As container orchestration continues to evolve, embracing its capabilities not only enhances operational efficiency but also drives innovation in modern IT infrastructures.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>containers</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Jenkins</title>
      <dc:creator>gurunadh</dc:creator>
      <pubDate>Sat, 10 Aug 2024 17:04:25 +0000</pubDate>
      <link>https://dev.to/gurunadh234/jenkins-15im</link>
      <guid>https://dev.to/gurunadh234/jenkins-15im</guid>
      <description>&lt;p&gt;Jenkins is an automation tool widely used for Continuous Integration (CI) and Continuous Delivery (CD). It helps&lt;br&gt;
automate various stages of the software development process, including building, testing and deploying.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pipeline&lt;/strong&gt;&lt;br&gt;
In Jenkins, to automate the stages of the software development process, we can define a &lt;em&gt;pipeline&lt;/em&gt;. A pipeline is a set of&lt;br&gt;
stages that are linked together to form a processing system, executed sequentially.&lt;/p&gt;

&lt;p&gt;A Jenkins pipeline can be in two formats.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Declarative format&lt;/li&gt;
&lt;li&gt;Scripted format&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Both formats are written in Groovy. The Scripted pipeline provides more flexibility than the Declarative format but is more verbose.&lt;br&gt;
We will discuss Declarative format.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Basic Structure
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;Basic structure of a pipeline consists of&lt;br&gt;&lt;br&gt;
&lt;strong&gt;P&lt;/strong&gt; — pipeline&lt;br&gt;&lt;br&gt;
&lt;strong&gt;A&lt;/strong&gt; — agent&lt;br&gt;&lt;br&gt;
&lt;strong&gt;S&lt;/strong&gt; — stages&lt;br&gt;&lt;br&gt;
&lt;strong&gt;S&lt;/strong&gt; — stage&lt;br&gt;&lt;br&gt;
&lt;strong&gt;S&lt;/strong&gt; — steps  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pipeline&lt;/strong&gt; — all stages, steps, post actions etc. will be defined in this block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Pipeline configuration written here&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Agent&lt;/strong&gt; — is a node or container that connects to a Jenkins controller and executes tasks as directed by the Jenkins&lt;br&gt;
controller. To use any available node or agent, we can use the &lt;em&gt;any&lt;/em&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stages&lt;/strong&gt; — define the sequence of stages that will be executed in a pipeline. We can have only one &lt;em&gt;stages&lt;/em&gt; block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;stages&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Consists of different stage executions&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stage&lt;/strong&gt; — is used to define the steps to execute a process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;stages&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;stage&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Stage name"&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="c1"&gt;// Consists of steps to execute a stage&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Steps&lt;/strong&gt; — used to define set of instructions to perform in a stage. Only one &lt;em&gt;steps&lt;/em&gt; block is allowed in a stage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;stages&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;stage&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Stage name"&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Set of instructions of the stage&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Basic Structure&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;stages&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;stage&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Build"&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Build stage"&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;stage&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Test"&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Test stage"&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;stage&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Quality"&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Quality stage"&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;stage&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Deploy"&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Deploy stage"&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Timeout &amp;amp; Retry
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Timeout
&lt;/h4&gt;

&lt;p&gt;Sometimes build can hang, due to unresponsive process, in that case we can wrap the step using &lt;em&gt;timeout&lt;/em&gt;, when a step takes long time then expected, timeout will abort the pipeline.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;stages&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Deploy"&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;time:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;unit:&lt;/span&gt; &lt;span class="s1"&gt;'MINUTES'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"./deploy.sh"&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this pipeline, if deploy.sh script takes more than 3 minutes, timeout will abort the pipeline.  &lt;/p&gt;

&lt;h4&gt;
  
  
  Retry
&lt;/h4&gt;

&lt;p&gt;When there is an exception while executing a stage sometimes retrying would solve the case. In Jenkins we can &lt;em&gt;retry&lt;/em&gt; block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;stages&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Deploy"&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;retry&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"./deploy.sh"&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, deploy.sh script will be executed at max 3 times, if there is an exception.  &lt;/p&gt;

&lt;p&gt;We can use timeout inside retry block and vice versa. If we want to retry the steps for &lt;em&gt;n&lt;/em&gt; times but don't want to spend more than &lt;em&gt;m&lt;/em&gt; minutes, we can nest retry block inside timeout block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;stages&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Deploy"&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;time:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;unit:&lt;/span&gt; &lt;span class="s1"&gt;'SECONDS'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;retry&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
                        &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"./deploy.sh"&lt;/span&gt;
                    &lt;span class="o"&gt;}&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, pipeline will fail if total time exceeds 3 minutes, or script throws exception even after 3 times.&lt;/p&gt;

&lt;p&gt;If we want to retry for &lt;em&gt;n&lt;/em&gt; times with &lt;em&gt;m&lt;/em&gt; minutes for each retry, we can next timeout in a retry block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;stages&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Deploy"&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;retry&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
                    &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;time:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;unit:&lt;/span&gt; &lt;span class="s1"&gt;'MINUTES'&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
                        &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s1"&gt;'./deploy.sh'&lt;/span&gt;
                    &lt;span class="o"&gt;}&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Post Actions
&lt;/h3&gt;

&lt;p&gt;Post block in Jenkins pipeline is used to handle tasks not limited to, sending notifications, cleanup, and archiving artifacts, at the end of pipeline based on the outcome of pipeline.&lt;br&gt;
Post block is a sibling block to stages.&lt;br&gt;
Some of the post actions are:&lt;/p&gt;
&lt;h4&gt;
  
  
  always
&lt;/h4&gt;

&lt;p&gt;Used to execute set of actions irrespective of pipeline outcome. It has high priority and runs first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;always&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Always block will get executed irrespective of pipeline status"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  changed
&lt;/h4&gt;

&lt;p&gt;Executes if pipeline's current state differs from previous state and will be executed just after &lt;em&gt;always&lt;/em&gt; block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Pipeline state defers from previous state"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  success
&lt;/h4&gt;

&lt;p&gt;Executes only if pipeline completes successfully.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;success&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Executes if pipeline completes successfully"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  failure
&lt;/h4&gt;

&lt;p&gt;Executes only if pipeline fails.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;failure&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Executes if pipeline fails"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  aborted
&lt;/h4&gt;

&lt;p&gt;Executes if pipeline is aborted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;aborted&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Pipeline is aborted"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  unstable
&lt;/h4&gt;

&lt;p&gt;Executes when pipeline is marked as unstable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;unstable&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Pipeline is unstable"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  unsuccessful
&lt;/h4&gt;

&lt;p&gt;Executes when the pipeline is aborted, failed, or unstable. &lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
    post {
        unsuccessful {
            sh "echo Pipeline did not complete successfully"
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  fixed
&lt;/h4&gt;

&lt;p&gt;Executed when the pipeline’s current state is successful and the previous state was failed or unstable. &lt;br&gt;&lt;br&gt;
When post block has both &lt;em&gt;success&lt;/em&gt; and &lt;em&gt;fixed&lt;/em&gt; blocks, the fixed block will be executed before success block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fixed&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Pipeline fixed"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  regression
&lt;/h4&gt;

&lt;p&gt;In general regression refers to a situation where there is a decline or deterioration in quality or performance.&lt;br&gt;&lt;br&gt;
In the context of Jenkins, regression block get executed, when the pipeline’s current state deteriorates from a previous successful or unstable state to a failed, aborted, or unstable state, but both the previous and current states cannot be unstable at the same time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;regression&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"echo Pipeline deteriorated to ${currentBuild.currentResult}"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  cleanup
&lt;/h4&gt;

&lt;p&gt;Used for removing or managing resources and files that are not needed after a build has completed. This ensures workspace remains clean and helps avoid potential issues from leftover files from previous builds. &lt;br&gt;&lt;br&gt;
It will be executed after all post blocks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
    &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;cleanup&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"./clean-up.sh"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>jenkins</category>
      <category>devops</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
