'How to grep kubectl output to the Jenkins variable

I have kubernetes job and I would like to get his pod logs in the jenkins pipeline.

So I try to grep pod name to the jenkins variable and then get logs.

POD_NAME = sh script: "kubectl describe jobs.batch ${JOB_NAME} | grep 'Created pod' | cut -d':' -f2"

echo "${POD_NAME}"

sh "kubectl logs --follow ${POD_NAME}"

But I got null in the POD_NAME variable.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source