kubectl port-forward using Jenkins parallel stages execution

1/11/2022

I'm trying to do a kubectl port-forward for tunnelling and execute a post request via curl to an endpoint setup via tunnelling like shown below but cannot let the curl job to be run until the kubectl port-forward has established tunnelling. Is there a way I could ensure the port-forward has been established for tunnelling before I go to the next step in a Jenkins pipeline. Is there any other alternative to achieve the same via Jenkins pipeline and shared libraries ?

stage("execute") {
      parallel {
        stage("curl refresh") {
          steps {
            sh "curl http://127.0.0.1:8001/actuator/refresh -d {} -H \"Content-Type: application/json\""
          }
        }
        
        
        stage("asdf asdf refresh") {
          steps {
            sh "kubectl port-forward po/\$pods 8001:9080 -n ${namespace}"
          }
        }
      }
  }
-- Avi
jenkins
jenkins-groovy
jenkins-pipeline
kubernetes

0 Answers