<p>I have a test.sh file which need to be run in an docker container which runs inside the Kubernetes pods via Jenkins job.</p>

<p>Flow: </p>

<p>Step1 : Run a Jenkins job which should login to a docker container running inside the pods</p>

<p>Step: From the container execute the test.sh script.</p>

<p>test.sh</p>

<p>echo "This is demo file"</p>

<p>I have a command which will give docker image running in a kubenertes pods</p>

<p><code>kubectl get pods -n eum -o go-template --template="{{range .items}}{{range .spec.containers}}{{.image}} {{end}}{{end}}" -l app=${TIER}</code></p>

<p>TIER = list of apps added in jenkins as choice parameter</p>

<p>I wanted to login to the container and run the test.sh script</p>

Suresh Ravi
<p>You can use command "kubectl exec ${POD } /bin/bash --all-namespaces -- /bin/sh test.sh" to run directly test.sh inside container, but make sure test.sh is available inside container. But in this case you need to pass pod name in this command. you can get all pods name using command</p>

<p>kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'</p>

<p>and if you want pods only for specific label then use</p>

<p>kubectl get pods -l  -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'</p>

<p>here replace  with your label selector of pods</p>
