<?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"><channel><title><![CDATA[Parameterized Jenkins Pipeline]]></title><description><![CDATA[Parameterized Jenkins Pipeline]]></description><link>https://parameterized.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 15:07:33 GMT</lastBuildDate><atom:link href="https://parameterized.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Mastering Parameterized Jenkins Pipelines: A Step-by-Step Guide for Dynamic Builds]]></title><description><![CDATA[Introduction
When working with CI/CD in Jenkins, flexibility is key. What if you want to build different branches, deploy to different environments, or control whether certain stages should run?
That’s where Parameterized Pipelines come into play.
In...]]></description><link>https://parameterized.hashnode.dev/mastering-parameterized-jenkins-pipelines-a-step-by-step-guide-for-dynamic-builds</link><guid isPermaLink="true">https://parameterized.hashnode.dev/mastering-parameterized-jenkins-pipelines-a-step-by-step-guide-for-dynamic-builds</guid><category><![CDATA[ Jenkins ✅ CI/CD ✅ DevOps ✅ Automation ✅ Tutorial]]></category><dc:creator><![CDATA[Sandeep Lagishetti]]></dc:creator><pubDate>Tue, 15 Jul 2025 16:40:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1752596573012/15415896-721c-41fb-aee8-f5716eb8dbb1.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-introduction">Introduction</h3>
<p>When working with CI/CD in Jenkins, flexibility is key. What if you want to build different branches, deploy to different environments, or control whether certain stages should run?</p>
<p>That’s where <strong>Parameterized Pipelines</strong> come into play.</p>
<p>In this blog, we’ll walk through creating a fully functional <strong>parameterized pipeline in Jenkins</strong> using <strong>String</strong>, <strong>Choice</strong>, and <strong>Boolean</strong> parameters — along with real-world pipeline code to deploy to Git, SonarQube, Nexus, and Tomcat.</p>
<p>Let’s get started!</p>
<hr />
<h2 id="heading-steps-to-create-a-parameterized-pipeline-in-jenkins">Steps to Create a Parameterized Pipeline in Jenkins</h2>
<hr />
<h3 id="heading-step-1-create-a-new-pipeline-job">Step 1: Create a New Pipeline Job</h3>
<ul>
<li><p>Go to your <strong>Jenkins Dashboard</strong></p>
</li>
<li><p>Click <strong>“New Item”</strong></p>
</li>
<li><p>Give your project a name (e.g., <code>Parameterized-Pipeline</code>)</p>
</li>
<li><p>Select <strong>“Pipeline”</strong></p>
</li>
<li><p>Click <strong>OK</strong></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752593509789/e62762d7-6853-488a-9046-be20c0bdbc3d.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<hr />
<h3 id="heading-step-2-enable-build-parameters">Step 2: Enable Build Parameters</h3>
<ul>
<li><p>Inside your project configuration:</p>
<ul>
<li><p>Go to the <strong>“General”</strong> section</p>
</li>
<li><p>Check the box for <strong>“This project is parameterized”</strong></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752593824843/8dd01011-94a4-4d68-ae1f-5fc675f8e456.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ul>
<hr />
<h3 id="heading-step-3-add-parameters">Step 3: Add Parameters</h3>
<p>Now let’s add three types of parameters that the pipeline will use.</p>
<hr />
<h4 id="heading-1-string-parameter">1. <strong>String Parameter</strong></h4>
<ul>
<li><p>Click <strong>“Add Parameter” &gt; String Parameter</strong></p>
</li>
<li><p>Fill in the details:</p>
<ul>
<li><p><strong>Name:</strong> <code>BRANCH_NAME</code></p>
</li>
<li><p><strong>Default Value:</strong> <code>development</code></p>
</li>
<li><p><strong>Description:</strong> Git branch to build</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752594340181/385a24bf-1545-4f84-82a1-1d59f4eb1796.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ul>
<hr />
<h4 id="heading-2-choice-parameter">2. <strong>Choice Parameter</strong></h4>
<ul>
<li><p>Click <strong>“Add Parameter” &gt; Choice Parameter</strong></p>
</li>
<li><p>Fill in the details:</p>
<ul>
<li><p><strong>Name:</strong> <code>ENVIRONMENT</code></p>
</li>
<li><p><strong>Choices:</strong></p>
<pre><code class="lang-plaintext">  rCopyEditdev
  qa
  prod
</code></pre>
</li>
<li><p><strong>Description:</strong> Deployment environment</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752594367216/7743d368-4e1b-4ed7-8ffe-d55ac9820f22.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ul>
<hr />
<h4 id="heading-3-boolean-parameter">3. <strong>Boolean Parameter</strong></h4>
<ul>
<li><p>Click <strong>“Add Parameter” &gt; Boolean Parameter</strong></p>
</li>
<li><p>Fill in the details:</p>
<ul>
<li><p><strong>Name:</strong> <code>DEPLOY_TO_TOMCAT</code></p>
</li>
<li><p><strong>Default Value:</strong> checked (true)</p>
</li>
<li><p><strong>Description:</strong> Deploy WAR to Tomcat?</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752594435533/f8f17727-837f-4632-9bd4-c3a52a4a745a.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ul>
<hr />
<h3 id="heading-step-4-add-pipeline-code">Step 4: Add Pipeline Code</h3>
<p>Scroll down to the <strong>Pipeline</strong> section and choose <strong>Pipeline Script</strong>.</p>
<p>Paste the following code:</p>
<pre><code class="lang-plaintext">groovyCopyEdit// Jenkins Declarative Pipeline with Parameters
pipeline {
    agent any

    tools {
        maven "maven-3.9.9"
    }

    parameters {
        string(name: 'BRANCH_NAME', defaultValue: 'development', description: 'Git branch to build')
        choice(name: 'ENVIRONMENT', choices: ['dev', 'qa', 'prod'], description: 'Deployment environment')
        booleanParam(name: 'DEPLOY_TO_TOMCAT', defaultValue: true, description: 'Deploy WAR to Tomcat?')
    }

    stages {
        stage('Git Checkout') {
            steps {
                echo "Checking out branch: ${params.BRANCH_NAME}"
                git branch: "${params.BRANCH_NAME}", url: 'https://github.com/Bancslink/my-web-app-project.git'
            }
        }

        stage('Build') {
            steps {
                sh "mvn clean package"
            }
        }

        stage('SonarQube Report') {
            steps {
                sh "mvn sonar:sonar"
            }
        }

        stage('Deploy to Nexus') {
            steps {
                sh "mvn deploy"
            }
        }

        stage('Deploy to Tomcat') {
            when {
                expression { return params.DEPLOY_TO_TOMCAT }
            }
            steps {
                echo "Deploying WAR file to Tomcat in environment: ${params.ENVIRONMENT}"
                sh """
                    curl -u sandeep:1234 \
                        --upload-file /var/lib/jenkins/workspace/Declarative-pipeline-jio/target/maven-web-application.war \
                        "http://3.111.169.249:8000/manager/text/deploy?path=/maven-web-application&amp;update=true"
                """
            }
        }
    }
}
</code></pre>
<p>Click <strong>Save</strong>.</p>
<p>The <code>parameters</code> block declares <em>build parameters</em>, which means <strong>when you click “Build with Parameters,” Jenkins will show these options in the UI</strong>, so you can customize how the job runs.</p>
<hr />
<h3 id="heading-line-by-line-explanation">Line by Line Explanation</h3>
<hr />
<h3 id="heading-1-string">1) <code>string(...)</code></h3>
<pre><code class="lang-plaintext">groovyCopyEditstring(
    name: 'BRANCH_NAME',
    defaultValue: 'development',
    description: 'Git branch to build'
)
</code></pre>
<ul>
<li><p><strong>Parameter Type</strong>: String (text input field)</p>
</li>
<li><p><strong>Name</strong>: <code>BRANCH_NAME</code> (variable you reference as <code>params.BRANCH_NAME</code>)</p>
</li>
<li><p><strong>Default Value</strong>: <code>'development'</code> (pre-filled in the UI)</p>
</li>
<li><p><strong>Description</strong>: shows the help text “Git branch to build”<br />  <strong>Use Case:</strong><br />  If you want to build a specific branch (e.g., <code>feature/login</code>), you enter it here.</p>
</li>
</ul>
<hr />
<h3 id="heading-2choice">2)<code>choice(...)</code></h3>
<pre><code class="lang-plaintext">groovyCopyEditchoice(
    name: 'ENVIRONMENT',
    choices: ['dev', 'qa', 'prod'],
    description: 'Deployment environment'
)
</code></pre>
<ul>
<li><p><strong>Parameter Type</strong>: Choice (dropdown menu)</p>
</li>
<li><p><strong>Name</strong>: <code>ENVIRONMENT</code></p>
</li>
<li><p><strong>Choices</strong>: <code>['dev', 'qa', 'prod']</code></p>
<ul>
<li>The user selects one of these options.</li>
</ul>
</li>
<li><p><strong>Description</strong>: explains the purpose of the dropdown.<br />  <strong>Use Case:</strong><br />  Deploy to <strong>Dev</strong>, <strong>QA</strong>, or <strong>Production</strong> environment depending on the selection.</p>
</li>
</ul>
<hr />
<h3 id="heading-3-booleanparam">3) <code>booleanParam(...)</code></h3>
<pre><code class="lang-plaintext">groovyCopyEditbooleanParam(
    name: 'DEPLOY_TO_TOMCAT',
    defaultValue: true,
    description: 'Deploy WAR to Tomcat?'
)
</code></pre>
<ul>
<li><p><strong>Parameter Type</strong>: Boolean (checkbox)</p>
</li>
<li><p><strong>Name</strong>: <code>DEPLOY_TO_TOMCAT</code></p>
</li>
<li><p><strong>Default Value</strong>: <code>true</code> (checked by default)</p>
</li>
<li><p><strong>Description</strong>: instructs the user what this toggle controls.<br />  <strong>Use Case:</strong><br />  If checked, the pipeline deploys to Tomcat after the build. If unchecked, it skips deployment.</p>
</li>
</ul>
<hr />
<p><strong>How you use them in your pipeline</strong><br />You reference them via:</p>
<pre><code class="lang-plaintext">groovyCopyEditparams.BRANCH_NAME
params.ENVIRONMENT
params.DEPLOY_TO_TOMCAT
</code></pre>
<p>For example:</p>
<pre><code class="lang-plaintext">groovyCopyEditgit branch: "${params.BRANCH_NAME}"
when { expression { return params.DEPLOY_TO_TOMCAT } }
</code></pre>
<hr />
<p><strong>Bottom Line:</strong><br />This block makes your pipeline <strong>flexible and reusable</strong>, so a single job can build any branch, deploy to any environment, and optionally skip deployment.</p>
<hr />
<h3 id="heading-step-5-build-with-parameters">Step 5: Build with Parameters</h3>
<ul>
<li><p>Go back to the Jenkins Dashboard</p>
</li>
<li><p>Click on your pipeline project (e.g., <code>Parameterized-Pipeline</code>)</p>
</li>
<li><p>Select <strong>“Build with Parameters”</strong></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752594886113/648c5153-ec05-4497-994d-e657984d4037.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>You’ll see three fields:</p>
<ul>
<li><p><strong>Git Branch Name</strong></p>
</li>
<li><p><strong>Deployment Environment</strong></p>
</li>
<li><p><strong>Deploy WAR to Tomcat?</strong></p>
</li>
</ul>
</li>
<li><p>Fill them in or keep defaults, then click <strong>Build</strong></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752594909001/bd86a331-b36b-4666-b06a-6daeaf31dec9.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Once build starts it shows build number and final build steps here.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752595702879/fe546e49-6c44-486d-bfb5-fa4ca0ecbce3.png" alt class="image--center mx-auto" /></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752595716361/9f2297a5-cf99-4100-a476-e746fbcc83c5.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<hr />
<h3 id="heading-done-what-happens-now">Done! What Happens Now?</h3>
<ul>
<li><p>Jenkins checks out the selected Git branch</p>
</li>
<li><p>Builds the code using Maven</p>
</li>
<li><p>Sends code quality analysis to SonarQube</p>
</li>
<li><p>Publishes artifacts to Nexus</p>
</li>
<li><p>Optionally (if checkbox is checked), deploys WAR to Tomcat</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752595506544/423cc84c-7ff7-4aa8-a043-38f61ff56932.png" alt class="image--center mx-auto" /></p>
<p>  Click on /maven-web-application it will open final output as below</p>
</li>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752595961576/64032fa9-15a3-4056-b938-4842da104d4f.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>With Parameterized Pipelines in Jenkins, you unlock powerful, reusable, and customizable CI/CD workflows that can adapt to different environments and use cases.</p>
<p>Whether you're a DevOps engineer or developer, mastering this feature helps you automate smarter, reduce duplication, and increase flexibility.</p>
]]></content:encoded></item></channel></rss>