Run a bash script from a docker container running in kubernetes pod via Jenkins job

7/23/2019

I am able to login to the container running in a pod using kubectl exec -t ${POD } /bin/bash --all-namespaces (POD is the text parameter value in my Jenkins job, In which user would have entered the pod name before running the job), Now my question is : I am able to login into the container , I want to my test.sh file from the logged in container ? Flow:

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

Step: From the container execute the test.sh script.

test.sh

echo "This is demo file"

-- Suresh Ravi
docker
jenkins
kubernetes

1 Answer

7/24/2019

There is no need to have two steps one step is sufficient. I believe below should get the job done

kubectl exec ${POD} /path/to/script/test.sh --all-namespaces

Below is the reference form Kubernetes documentation

kubectl exec my-pod -- ls / # Run command in existing pod (1 container case)

kubectl exec my-pod -c my-container -- ls / # Run command in existing pod (multi-container case)

-- asolanki
Source: StackOverflow