<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Subir on Medium]]></title>
        <description><![CDATA[Stories by Subir on Medium]]></description>
        <link>https://medium.com/@subirrastogi?source=rss-2ada72884423------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LkAC6aEZ7FsPCaOMfFozFg.jpeg</url>
            <title>Stories by Subir on Medium</title>
            <link>https://medium.com/@subirrastogi?source=rss-2ada72884423------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:41:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@subirrastogi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Java Streams: Think before Parallelizing Streams]]></title>
            <link>https://medium.com/@subirrastogi/java-streams-think-before-parallelizing-streams-fa328bfaab6c?source=rss-2ada72884423------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa328bfaab6c</guid>
            <dc:creator><![CDATA[Subir]]></dc:creator>
            <pubDate>Mon, 20 May 2024 11:04:10 GMT</pubDate>
            <atom:updated>2024-05-20T11:04:10.570Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*2X2RbemmfreQ4528EUy3eg.jpeg" /></figure><p>Java Streams API has made it very easy to process data in parallel. Any Stream can be made parallel by calling <a href="https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/util/stream/BaseStream.html#parallel()">parallel(</a>) on Stream.</p><p>Even though it’s easy to use, processing data in parallel is not always going to be faster as compared to sequential.</p><p>The objective of this article is to explain few critical things that you should keep in mind while deciding whether a stream should be executed in sequential vs parallel.</p><h4>How does Parallel Stream work?</h4><p>Let’s take an example to understand</p><pre>int sum = Arrays.stream(new int[]{1, 2, 3, 4})          // (1)<br>                        .parallel()                     // (2)<br>                        .sum();                         // (3)</pre><p>In simple terms, below are the steps which will executed:</p><ol><li>Splitting of source data — Parallel Streams will split source data into parts recursively. Fork/Join Framework is used internally, and each worker thread will work on partial data. In the example mentioned at Line — (1), source data is an integer array. Line — (2) converts stream to parallel and internally source data will be split.</li><li>As per Stream pipeline, on partial data lambda expression are applied and partial result is generated. In the example mentioned, there are no intermediate stream operations.</li><li>Finally, terminal operation — sum is used, partial results are merged into single result and Stream is completed. In the example mentioned, think like this source array has been split into two sub-arrays and sum is calculated for each sub-array. In the end, the sum of each sub-array will be added to produce final sum.</li></ol><p>Now let’s look at important things that should be kept in mind in deciding whether a stream should be executed in sequential vs parallel.</p><ol><li><strong>How efficiently Source Data can be split?</strong><br>It should be cheap to split source data to get benefits from parallel processing.</li><li><strong>What kind of Lambda expressions or method references should be used during processing Stream?</strong> <br>Here the point is that if lambda expressions had to hold an internal state, sharing this internal state across threads is going to be costly.<br>More details are mentioned later.</li><li>Even if you have followed above points, It’s still quite important to <strong>measure stream performance of sequential vs parallel</strong> to conclude if parallel streams should be used.</li></ol><p>Let’s discuss each point in more detail.</p><h4>Point#1 — How efficiently Source Data can be split?</h4><ul><li>Stream can be created from Collection and choice of collection data structure plays an important role.<br>Some Collections are easy and cheap to split as compared to others.<br>For e.g. — ArrayList can be easily split in middle as compared to LinkedList. To split LinkedList, it will require to traverse from start to middle which is not efficient.</li><li>Using IntStream.range() as compared to Stream.generate() or Stream.iterate().<br>IntStream.range(0, 5) can easily be split as results are like array and predictable.<br>Stream.generate() and Stream.iterate() create infinite stream and are used with .limit(). They are not easily split as it requires to analyze complete stream.</li></ul><p>So, it’s important to understand if it’s cheap or expensive to split source data.</p><h4>Point#2 — What kind of Lambda expressions or method references should be used during processing Stream?</h4><p>As per official java <a href="https://docs.oracle.com/en%2Fjava%2Fjavase%2F22%2Fdocs%2Fapi%2F%2F/java.base/java/util/stream/package-summary.html">docs</a>, following are the key characteristics of lamdba expressions:</p><ol><li><strong>Non-interference </strong>— It means to ensure that non-concurrent data sources should not be modified at all during execution of the Stream Pipeline. It can cause exceptions or inconsistent behavior.</li><li><strong>Stateless behavior </strong>— Stateful lambda are those who need to carry an internal state. Sharing internal state between threads is going to be costly. Stateful lambdas should be avoided with parallel streams, and will have impact on performance.<br>There are few stateful operations which keeps track of order like — limit(), skip() and findFirst(). These operations lead to overheads in parallel streams and should be avoided.</li><li><strong>Side Effects</strong> — Side effects means when Lambda expressions access any external state. Access to any noncurrent state will lead to race condition and data inconsistency. <br>Lambda expressions should be <em>side effects free. </em>It’s recommended to use reduction operations provided by Stream over mutable accumulators.</li><li><strong>Merging of partial result</strong> — How expensive is it to merge partial results? To merge two integers to calculate sum is cheap, merging Arraylist is also cheap where as merging HashMap is costly.<br>Collectors API provides useful alternatives — <a href="https://docs.oracle.com/en%2Fjava%2Fjavase%2F22%2Fdocs%2Fapi%2F%2F/java.base/java/util/stream/Collectors.html#groupingByConcurrent(java.util.function.Function)">groupingByConcurrent</a>() to improve performance.</li></ol><p>Side-Effect Example — In the below example ,forEach() terminal operation is accessing shared mutable accumulator — ArrayList and will result in data inconsistency and should be avoided.</p><pre>//Bad example<br>List&lt;Integer&gt; ints = new ArrayList&lt;&gt;();<br><br>IntStream.range(0, 1_000_000)<br>         .boxed()<br>         .parallel()<br>         .forEach(ints::add);<br><br>System.out.println(&quot;ints.size() = &quot; + ints.size());</pre><p>Above code can be refactored to use reduction operation provided by Steam — collect(). Using reduction operations provided by Streams are <a href="https://docs.oracle.com/en%2Fjava%2Fjavase%2F22%2Fdocs%2Fapi%2F%2F/java.base/java/util/stream/package-summary.html#MutableReduction">safer </a>to be used with Parallel Streams.</p><pre>List&lt;Integer&gt; ints = IntStream.range(0, 1_000_000)<br>                                      .boxed()<br>                                      .parallel()<br>                                      .collect(Collectors.toList());</pre><h4>Point#3 — Measure Stream performance sequential vs parallel.</h4><p>Parallel Streams tends to perform better with significantly large amount of data and for smaller data size, sequential streams are better.</p><p>Let’s take a very simple example to calculate sum of integers. To measure performance, I am following the approach taken by this <a href="https://blogs.oracle.com/javamagazine/post/java-parallel-streams-performance-benchmark">article</a>. Here is what we will do:</p><ol><li>We will calculate sum of integers for following counts — 1,000, 10,000, 100,000, 1,000,000.</li><li>We will 3 implementation to calculate sum — one sequential, one parallel and one as simple iterative loop.</li><li>To measure time take — each implementation for a respective value will be run <strong>100 times</strong> and average time will be taken.</li></ol><p>When I run this program on my pc, I see following results:</p><pre>Streams created with the rangeClosed() method:<br> Size Sequential Parallel<br>   1000   0.03453   0.07270<br>  10000   0.01731   0.02719<br> 100000   0.03608   0.04716<br>1000000   0.32426   0.24029                    // (1)<br>Iterative solution with an explicit loop:<br> Size Iterative<br>   1000   0.00916<br>  10000   0.02422<br> 100000   0.05162<br>1000000   0.30563<br>All Times are in milliseconds</pre><p>If you notice Line-(1), it’s only for 1,000,000 that parallel stream performed better than sequential. For all other cases, sequential steam performed better than parallel.</p><p>In this example, source data is created via IntStream.rangeClosed() which can be easily split and results of partial sum operations can be easily merged.</p><p>To summarize, following are the key points to remember in order to get performance gains from Parallel Streams:</p><ol><li>It should be cheap to split source data</li><li>lambda expressions used should be Non-Interfering, Stateless and Side-Effect Free. They should also not maintain order or any other internal state.</li><li>Parallel Stream performs better on significantly large size of data so always measure performance.</li></ol><p>All code can be found at this GitHub <a href="https://github.com/subirrastogi/java-parallel-streams">repo</a>.</p><h4>Want to dig dipper?</h4><p>Here are the resources I recommend:</p><ul><li><a href="https://dev.java/learn/api/streams/parallel-streams/">dev.java</a> article on Parallel Streams. This article will provide you more information on concepts like <em>Data Locality</em> and <em>pointer chasing </em>which are quite useful. This article also covers more details on Fork/Join Framework and explain concepts like <em>work stealing</em>.</li><li>Java Official <a href="https://docs.oracle.com/en%2Fjava%2Fjavase%2F22%2Fdocs%2Fapi%2F%2F/java.base/java/util/stream/package-summary.html">Docs </a>which explains in great detail about key things to keep in mind while writing efficient lambdas and various reduction operations.</li></ul><p>Happy Learning!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa328bfaab6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Concurrent Programming in Java has evolved?]]></title>
            <link>https://medium.com/@subirrastogi/how-concurrent-programming-in-java-has-evolved-6cdf18cc2cdb?source=rss-2ada72884423------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cdf18cc2cdb</guid>
            <category><![CDATA[concurrent-programming]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Subir]]></dc:creator>
            <pubDate>Sat, 23 Mar 2024 07:22:37 GMT</pubDate>
            <atom:updated>2024-03-23T07:25:38.923Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f0jjVNHCsRe_3k_xdpbenQ.png" /></figure><h3>Background</h3><p>With the adoption of microservices architecture, Developer’s needs have evolved. Developers write smaller apps and consumes multiple external API’s. At the same time, Data volumes are growing so developers are required to build apps which</p><ul><li>should utilize multicore processors in order to increase throughput.</li><li>should be fault tolerant/ highly available. Slow external api’s or Network error should be handled gracefully.</li></ul><h3>How Java has evolved over time to help developers?</h3><p>Java has done significant changes over time to help Developers overcome these challenges.</p><ul><li>Starting from Java 5, <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html">Future </a>&amp; <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html">ExecutorService </a>was added to allow write better concurrent code instead of working directly with Threads. These changes were not enough to meet above criteria’s.</li><li>Major changes were released in Java 8 to allow us write better concurrent code using <a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html">Streams</a>, Parallel Streams and <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html">CompletableFuture class</a>.</li></ul><h3>10,000 Foot View — Why should you read this?</h3><p>Problem with multiple options is confusion — Developer gets confused with questions like — Which option is better to use —Future, Streams, Parallel Streams or CompletableFuture and more importantly why?</p><p>I was reading this book — <a href="https://www.manning.com/books/modern-java-in-action">Modern Java in Action</a> and found Chapter-15 and Chapter-16 so much useful and helped me understand — Why which option is better to use as per requirement? So this article ranges over it.</p><p>As the example given by the Author of the book, we will see sample problem statement and multiple Implementations:<br>– Sequential version using Basic Java code.<br>– Parallel version based Java Future Interface introduced in Java 1.5.<br>– Sequential version using Java 8 Streams.<br>– Using Java 8 Parallel Streams<br>– Using CompletableFuture introduced in Java 8.<br>– Using CompletableFuture based on custom executor</p><p>Later, based on new requirement, we will see few implementations does not scale well and we will be left with only two implementations — Parallel Streams or CompletableFuture with Custom Executor.</p><p>I hope by the end of this article, you will have</p><ul><li>Good understanding on concurrent programming in Java and how it has evolved overtime.</li><li>Why use CompletableFuture? What are various features provided by CompletableFuture class.</li><li>Building scalable and fault tolerant systems.</li></ul><p>You can find code on this <a href="https://github.com/subirrastogi/java-completable-future">GitHub repo</a>.</p><h3><strong>1,000 Foot View — Overview</strong></h3><p>To make it simpler, I have categorized all these implementations into 3 parts</p><ul><li><strong>Version-0:</strong> Implementation based on Java 7 &amp; earlier.</li><li><strong>Version-1:</strong> Implementation based on Java 8 utilizing Streams, Parallel Streams, CompletableFuture and CompletableFuture using custom executor.</li><li><strong>Version-2:</strong> Based on new requirement, implementations based on Streams, Parallel Streams and CompletableFuture.</li></ul><h3>Why CompletableFuture?</h3><p>CompletableFuture class was added in Java 8</p><ol><li>as there were significant limitations with existing Future Interface where one can not easily combine two asynchronous computations.</li><li>to be to react to Future Completion and then be able to build a pipeline of perform further blocking/non-blocking actions. This is done by adding methods like .supplyAsync() and .thenCompose().</li><li>Fail with exception and much more.</li></ol><h3>Let’s get started</h3><p><strong>Problem Statement</strong></p><p>As mentioned by Book Author, Goal is to develop Best Price Finder app which will connect to multiple Shops and get the price of the product.</p><p>Key requirements are:</p><ol><li><strong>Fast Response Time</strong>: Best Price Finder App should be extremely fast in gathering prices from various shops and display to users as quickly as possible.</li><li><strong>Scalable</strong>: It should be possible to scale this App to connect to large no. of Shops.</li><li><strong>Error Handling</strong> and App should be able to manage network errors/ slow responses while getting prices from various Shops.</li><li><strong>Easily Extendable</strong> — It should be easy to integrate future requirements like — to show discount prices for a product for various types of members of Best Price Finder App.</li></ol><p><strong>Implementations</strong></p><p>Let’s see multiple implementations :</p><ol><li><strong>Version-0</strong>: Implementations based on Java 7 and earlier. In this Version, you will see two implementations — Sequentially and Using Java Future with ExecutorService. Refer this <a href="https://github.com/subirrastogi/java-completable-future/blob/main/src/main/java/example/modernjavainaction/ch16/v0/BestPriceFinder.java">code</a>.</li><li><strong>Version-1</strong>: Implementation based on Java 8 Streams. There will be 4 actual implementations: Using Streams Sequentially, Using Parallel Streams, Using CompletableFuture and Using CompletableFuture with custom Executors. Refer this <a href="https://github.com/subirrastogi/java-completable-future/blob/main/src/main/java/example/modernjavainaction/ch16/v1/BestPriceFinder.java">class</a>.</li><li><strong>Verson-2</strong>: Based on new requirement, Implementations — Using Streams Sequentially, and Using Parallel Streams and Using CompletableFuture with custom Executors. Refer <a href="https://github.com/subirrastogi/java-completable-future/blob/main/src/main/java/example/modernjavainaction/ch16/v2/BestPriceFinder.java">this</a>.</li></ol><p><strong>Results — Let’s compare time taken by each implementation</strong></p><p>Here are the results running on my desktop for 4, 5 and 9 Shops respectively.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35df337198d20c4161d5010926f06fd2/href">https://medium.com/media/35df337198d20c4161d5010926f06fd2/href</a></iframe><ol><li>I won’t be discussing about Version-0 as it has limitations explained earlier.</li><li>S.No#<strong>3</strong> &amp; S.No#<strong>7</strong>, processing done sequentially using Streams does not work well. With the new requirement, processing for 9 Shops took <strong>~18</strong> seconds.</li><li>S.No#<strong>4</strong> &amp; S.NO#<strong>8</strong>, processing done using Parallel Streams — It is fastest with 4 Shops but as the no. of shops increases, performance degraded. With the new requirement and 9 shops, it took <strong>~6</strong> seconds.</li><li><strong>Most important of all</strong>, look at the time taken by implementations S.No#<strong>6</strong> and S.No#<strong>9</strong> which is based on CompletableFuture with custom Executor. Even when we scale from 4 Shops to 5 and 9 shops respectively with the new requirement, time taken is still little more than 2 secs.</li><li>You may be curious — Why Parallel Streams is not as good as CompletableFuture with custom executor? Reason is Parallel Streams internally uses common pool with fixed number of Threads equal to Available Processors where as CompletableFuture class has the been built to take custom executor.</li><li>Using CompletableFuture class methods — .supplyAsync() and .thenCompose() allow us to built pipeline of asynchronous /non-blocking computations, hence performed better.</li></ol><h3>Conclusion</h3><p>I hope it’s clear by now how java has evolved over time and allowed Developers to write better code by adding classes like — <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html">CompletableFuture</a>. Solutions built using custom executors and CompletableFuture are quite powerful and allow us to meet the growing demands.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cdf18cc2cdb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Just enough Groovy for Jenkins Pipeline]]></title>
            <link>https://medium.com/@subirrastogi/just-enough-groovy-for-jenkins-pipeline-5444f4d0db4b?source=rss-2ada72884423------2</link>
            <guid isPermaLink="false">https://medium.com/p/5444f4d0db4b</guid>
            <category><![CDATA[pipeline-as-code]]></category>
            <category><![CDATA[jenkins-pipeline]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[groovy]]></category>
            <dc:creator><![CDATA[Subir]]></dc:creator>
            <pubDate>Sun, 03 Sep 2023 11:04:40 GMT</pubDate>
            <atom:updated>2023-09-08T13:13:35.567Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Why am I writing this article?</strong></p><p>As you know, Jenkins uses groovy in scripted pipeline. I see many Developers struggling with groovy and Jenkins pipeline. The main reason being that Developers has not spent time in learning fundamentals of groovy instead focused directly onto building pipelines.</p><blockquote>To be able to write clean and elegant pipeline code, it’s important to understand fundamentals of groovy.</blockquote><p>I am writing this article explaining basics of Groovy so that fundamentals are clear. This is a brief article only and contains pointers to the official documentation so that knowledge can be further enriched.</p><p><strong>What is Groovy?</strong></p><p>I quote from groovy <a href="https://groovy-lang.org/">official website</a>:</p><blockquote><a href="http://www.apache.org/">“Apache</a> Groovy is a <strong>powerful</strong>, <strong>optionally typed</strong> and <strong>dynamic</strong> language for the Java platform aimed at improving developer productivity thanks to a concise, <strong>familiar and easy to learn syntax</strong>.”</blockquote><p>Our aim here is to learn enough of Groovy in reference to Jenkins Pipeline. So key things to note here are:</p><ol><li>Groovy is built on top of <strong>Java </strong>and supports Java syntax.</li><li>Groovy has an easy to learn syntax.</li><li>Groovy is optionally typed and aimed at improving developer productivity. You will see later how.</li><li>Groovy code gets compiled to Java bytecode.</li></ol><p>Let’s see few examples.</p><p><strong>Example-1</strong></p><p>Simple Hello World example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iyQ2TXeS6feSXbgMY8Hu_w.png" /><figcaption>HellowWorld: Java vs Groovy</figcaption></figure><p>Couple of things to note:</p><ol><li>Semi-colons are optional.</li><li>Class and method definitions are not required.</li><li>No default imports are required. Groovy puts it automatically.</li><li>Groovy is lenient with parenthesis.</li><li>You would be wondering how <em>println </em>is working in Groovy. Groovy has extended <em>java.lang.Object </em>and added <em>println()</em> method so no need to use <em>System.out</em>. Groovy has actually extended JDK by adding convenience methods to various classes — <em>java.lang.Object</em>, <em>java.lang.String</em>, etc. and this library is called — <a href="http://www.groovy-lang.org/gdk.html">Groovy Development Kit ( GDK)</a>. This is reason Groovy says that it’s aimed at improving developer productivity.</li></ol><p><strong>Example-2</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nsJ5ttX1V55tozMfaaSNBw.png" /><figcaption>Class Syntax differences : Java vs Groovy</figcaption></figure><p>In Example-2, Two classes has been created — Person Class &amp; PersonTest and differences has been shown between Java &amp; Groovy.</p><p>Couple of things to note in Example-2:</p><ol><li>In Groovy — Properties and Methods can be defined with <strong>def</strong> and return type are optional. Property type is optional too. <em>This is why Groovy is called Dynamic Typed Language as at runtime types are inferred — methods and arguments are checked at runtime</em>. This is different than Java which does checks at compile-time.</li><li>Return statements are optional.</li><li>Methods and classes are public by default.</li><li>Flexible initialization &amp; Named Arguments — you will notice that there is no need to declare constructors. Groovy does it for you. We can use named arguments as highlighted in example.</li></ol><p><strong>Example-3</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G5A-LbdxqIehMQinDKNFXg.png" /></figure><p>On the right-hand side, you are seeing the output of Groovy script on left.</p><p><em>Groovy’ s String interpolation rules can sometimes be confusing.</em></p><p>Points to note here:</p><ol><li>Groovy treats single quote (<em>‘</em>) &amp; double quote (<em>“</em>) strings differently. Single quote strings are of type<em> java.lang.String</em> and double quote are type of <em>groovy.lang.GString</em> called <strong>Groovy String</strong>.</li><li>Single quotes are treated as pure literals and any expression inside it, Groovy does not evaluate it. This is why Output#1 did not work. Output#3 shows that <em>str1</em> is of type — <em>java.lang.String</em>.</li><li>Double quotes can have expression and Groovy will evaluate them. <em>This is called Groovy String Interpolation</em>. Output#2 worked correctly. Output#4 shows that it’s of type —<em> org.codehaus.groovy.runtime.GStringImpl</em>. <em>groovy.lang.GString</em> is super class of <a href="https://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/runtime/GStringImpl.html"><em>org.codehaus.groovy.runtime.GStringImpl</em></a>.</li><li>To use any variable in Groovy Strings, you can use the syntax- <em>“${expression}”</em>. {} are optional when the expression is a simple variable name.</li><li>You can use <em>‘’’ </em>for multiline string and <em>“”” </em>for<em> m</em>ultiline groovy string. Output#6 and Output#7 shows the results.</li></ol><p><strong>Jenkins best practices for using Groovy</strong>.</p><p>Jenkins also has published a set of best practices and you can find them <a href="https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#string-interpolation">here </a>and <a href="https://www.jenkins.io/doc/book/pipeline/pipeline-best-practices/">here</a>.</p><p>Key things to note are:</p><ol><li>Groovy string interpolation should never be used with credentials.</li><li>Groovy string interpolation can inject rouge commands for user-controlled variables and can result in problems analogous to SQL Injection.</li><li>Making sure to use Groovy code in Pipelines as glue only and avoid calling script from a single step.</li><li>Groovy code is always executed on Jenkins controller so it’s important to reduce the amount of Groovy code executed by Pipelines.</li><li>Avoiding complex Groovy code in Pipelines.</li></ol><p>That’s all for now and I hope this article helps you to be able to write clean and elegant pipeline.</p><p>Please let me know your comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5444f4d0db4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>