<p>We have a dockerized maven project where we deploy it to the kubernetes via Jenkins and Helm.So the thing that I would like to do is, pass below shell script as a command in deployment.yaml like as below to initate selenium tests while pod is creating. But somehow before I deploy the service, I need to update the variables in shell script according to the conditional statements(jenkins parameters) and then pass to update shell script to the kubernetes pod.</p>
<p>So, is there anyway to add if statements and update variables according to the jenkins parameters and pass through to pod with proper values ?</p>
<p><strong>Shell Script</strong></p>
<pre><code>#!/bin/sh
    
mvn --projects {$projectName} --also-make clean test -Dcucumber.filter.tags=&quot;@${servicename} or @${tag}&quot; -Denvironment=test -Ddhc=true -Djavax.net.ssl.trustStore=/usr/java/openjdk-14/lib/security/cacerts
</code></pre>
<p><strong>Deployment.yaml</strong></p>
<hr />
<pre><code>  env:
    {{- range $key, $value := .Values.extraEnv }}
    - name: {{ $key }}
      value: {{ $value | quote }}
    {{- end }}
  command: [&quot;/test-script.sh&quot;]
</code></pre>
<p><strong>Jenkinsfile</strong></p>
<hr />
<pre><code>parameters {    
    string(name: 'projectName', defaultValue: &quot;Xx&quot;, description: 'Which project do you want to test?')
    string(name: &quot;service_name&quot;, defaultValue: 'Yy', description: 'Selenium tag for service name')
    string(name: &quot;tag&quot;, defaultValue: 'must')
    //string(name:'branchName', defaultValue: &quot;origin/development&quot;, description: 'Environment for selenium tests')}

    stage('Deploy to dev'){
        steps{
            script{
                   sh &quot;&quot;&quot; 
                       helm upgrade --install --debugtest-service --values values.${ENV}.yaml --namespace ${namespace} --set image.tag=${env.BUILD_NUMBER} .
                     &quot;&quot;&quot;
                }
            }
</code></pre>
<p>EDIT-1</p>
<p>ı just added my question according to the below answer. So after running sed and update the script, how can I add a if statement to check value of service name parameter? Or can I use something like</p>
<pre><code>if [ &lt;PROJECTNAME&gt; == &quot;xx]
</code></pre>
<p>Here is the steps that I would like to do.</p>
<pre><code>    projectName=$1
    serviceName=$2
    tag=$3
    
    if [ &quot;$serviceName&quot; == &quot;xx&quot; ]
    then
        echo &quot;Tests are running &quot;..
        mvn --projects &lt;PROJECTNAME&gt; --also-make clean test -Dcucumber.filter.tags=&quot;&quot;@&lt;SERVICENAME&gt; or @&lt;TAG&gt;&quot;&quot; 
    else 
    echo 'All test scenarios are running on stage environment'
    mvn --projects &lt;PROJECTNAME&gt; --also-make clean test -Dcucumber.filter.tags=&quot;@&lt;SERVICENAME&gt; or @&lt;SERVICENAME&gt;&quot; -
    fi
</code></pre>

semural
<p>You can keep placeholders for such values which requires to be updated dynamically at build time.
I'd keep the shell-script as below with placeholders instead of variables:</p>
<pre class="lang-sh prettyprint-override"><code>#!/bin/sh
mvn --projects &lt;PROJECTNAME&gt; --also-make clean test -Dcucumber.filter.tags=&quot;@&lt;SERVICENAME&gt; or @&lt;TAG&gt;&quot; -Denvironment=test -Ddhc=true -Djavax.net.ssl.trustStore=/usr/java/openjdk-14/lib/security/cacerts
</code></pre>
<p>And then add a <code>sed</code> line within the <code>sh block</code> above your <code>helm upgrade ...</code> command to replace the placeholders with build time values so that it can passed to the next set of actions.</p>
<pre><code>sh &quot;&quot;&quot;
sed -i \&quot;s/&lt;PROJECTNAME&gt;/${projectName}/g; s/&lt;SERVICENAME&gt;/${service_name}/g; s/&lt;TAG&gt;/${tag}/g\&quot; /path/to/test-script.sh
helm upgrade . . . 
&quot;&quot;&quot;
</code></pre>
<p>EDIT-1:</p>
<pre><code>Example: 
if (serviceName == 'xx') {
    env.TAG = serviceName
} 
sh &quot;&quot;&quot;
.... other actions
&quot;&quot;&quot;
</code></pre>
