<p>I am writing a script to run in Jenkins as a job - which deletes kubernetes pvc's:</p>
<pre><code>node('example') {
    docker.withRegistry('https://registry.hub.docker.com', 'dockerhub-creds') {
         docker.image('example').inside() {
            sh &quot;kubectl describe -A pvc | grep -E &quot;^Name:.*$|^Namespace:.*$|^Mounted By:.*$&quot; | grep -B 2 &quot;&lt;none&gt;&quot; | grep -E &quot;^Name:.*$|^Namespace:.*$&quot; | cut -f2 -d: | paste -d &quot; &quot; - - | xargs -n2 bash -c 'kubectl -n ${1} delete pvc ${0}'&quot;
         }
    }
}
</code></pre>
<p>Now when I add this in the Jenkins item configure script area... it is giving me this error:</p>
<p><a href="https://i.stack.imgur.com/orUbF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/orUbF.png" alt="enter image description here" /></a></p>
<ul>
<li><p>error comes on line 4 which is the .. &quot;sh &quot;kubectl describe -A pvc ....&quot; line</p>
</li>
<li><p>what do I need to do to fix this?</p>
</li>
</ul>

devgirl
<p>I think the easiest way is to surround your command using <code>'''</code> (3 x single quotation mark).<br />
I've created example to illustrate you how it may work.</p>
<p>First I created two <code>PVCs</code> (<code>block-pvc</code>,<code>block-pvc2</code>) that should be removed by the script.</p>
<pre><code># kubectl get pvc -A
NAMESPACE   NAME         STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
default     block-pvc    Pending                                                     9m45s
test        block-pvc2   Pending                                                     9m42s
</code></pre>
<p>Then I added command to my pipeline:</p>
<pre><code>sh '''
    ./kubectl describe -A pvc | grep -E &quot;^Name:.*$|^Namespace:.*$|^Used By:.*$&quot; | grep -B 2 &quot;&lt;none&gt;&quot; | grep -E &quot;^Name:.*$|^Namespace:.*$&quot; | cut -f2 -d: | paste -d &quot; &quot; - - | xargs -n2 bash -c './kubectl -n ${1} delete pvc ${0}'
'''
</code></pre>
<p>As a result in the Console Output of this build we can see that it works as expected:</p>
<pre><code>persistentvolumeclaim &quot;block-pvc&quot; deleted
persistentvolumeclaim &quot;block-pvc2&quot; deleted
</code></pre>
