Search code examples
jenkinsgoogle-cloud-platformjenkins-pipelinegoogle-cloud-sql

Pipeline not moving to next stage


I am trying to connect to Google Cloud SQL via proxy from inside a jenkins node.

My Jenkinsfile looks like following.

Stage one works fine. My proxy is up & running and listening for incoming commands.

The issue is it never moves to the next stage. So I am unable to connect to the database.

Does any one know what can I do to overcome this issue or any other better way of doing this.

pipeline {
  agent any
  options {
    skipDefaultCheckout true
  }
  stages {
    stage('Install goole cloud sql proxy') {
      steps {
        dir(path: "${env.WORKSPACE}") {
          sh '''
                wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
                chmod +x cloud_sql_proxy
                ./cloud_sql_proxy -instances=INSTANCE_NAME=tcp:3306
             '''
        }
      }
    }
    stage('Connect to DB') {
      steps {
        dir(path: "${env.WORKSPACE}") {
          sh '''
                psql "host=127.0.0.1 port=3306 sslmode=disable dbname=postgres user=postgres"
            '''
        }
      }
    }
  }
}

Solution

  • I move my anwser from the comment here.

    Jenkins is simply blocking on the command ./cloud_sql_proxy -instances=INSTANCE_NAME=tcp:3306

    You can add a & at the end of the command to start in the background.