Jenkins pipeline code to get a SQL Dump

  • MYSQL_PWD=@credentials(=Pass-DB) mysqldump -h @credentials(=Prod-DB):@credentials(=Port-DB) -u @credentials(=User-DB) --ssl-mode=VERIFY_CA --ssl-ca=**** resonate
    mysqldump:
    Got error: 2005: Unknown MySQL server host ‘@credentials(=Prod-DB):@credentials(=Port-DB)’ (-2) when trying to connect

I received this error when I was trying to get a SQL dump using Jenkins pipeline. I want some assistance from fellow Jenkins user.

My Jenkinscode is:

pipeline {
agent {
node {
label ‘prod’
}
}
environment {
DB_USER = “${credentials(‘User-DB’)}”
DB_PASS = “${credentials(‘Pass-DB’)}”
DB_HOST = “${credentials(‘Prod-DB’)}”
DB_PORT = “${credentials(‘Port-DB’)}”
SQL_DUMP_FILE = “/home/devops/db-backup/my.sql”
}
stages {
stage(‘Generate SQL Dump’) {
steps {
withCredentials([file(credentialsId: ‘DB-CERT’, variable: ‘SSL_CA’)]) {
script {
// Set up the command
def command = “”"
MYSQL_PWD=${DB_PASS} mysqldump -h ${DB_HOST}:${DB_PORT} -u ${DB_USER} --ssl-mode=VERIFY_CA --ssl-ca=${SSL_CA} nextdb > ${SQL_DUMP_FILE}
“”"

                    // Execute the command
                    def exitCode = sh returnStatus: true, script: command

                    // Check the exit code
                    if (exitCode == 0) {
                        echo "SQL dump generated successfully"
                    } else {
                        error "Failed to generate SQL dump"
                    }
                }
            }
        }
    }
}

}

I re-entered the credentials and also added the production server(where the pipeline is running on) as allowed resources to cloud database.