How to get the output of kubectl describe deployment nginx | grep Image
in an environment variable?
My code:
stage('Deployment'){
script {
sh """
export KUBECONFIG=/tmp/kubeconfig
kubectl describe deployment nginx | grep Image"""
}
}
2
Answers
You can use the syntax:
In this situation, you can access the environment variables in the pipeline scope within the
env
object, and assign values to its members to initialize new environment variables. You can also utilize the optionalreturnStdout
parameter to thesh
step method to return thestdout
of the method, and therefore assign it to a Groovy variable (because it is within thescript
block in the pipeline).Note you would also want to place the
KUBECONFIG
environment variable within the environment directive at thepipeline
scope instead (unless the kubeconfig will be different in different scopes):