Connect to RDS database

0

How do I connect RDS DB in the Jenkins pipeline (Jenkinsfile)? What'd be the ORACLE_HOME with RDS?

asked 9 months ago560 views
1 Answer
0
Accepted Answer

Connecting to an RDS database from a Jenkins pipeline can be achieved using SQL scripts. You can utilize sqlplus command-line tool which is a part of Oracle Instant Client. It allows you to run SQL and PL/SQL commands and scripts on an Oracle database from Jenkins.

First, you need to install Oracle Instant Client on your Jenkins server and then make use of it in your Jenkinsfile.

Here is a generic Jenkinsfile that illustrates how you might connect to an Oracle RDS database:

pipeline {
    agent any

    stages {
        stage('Run SQL on RDS') {
            steps {
                sh '''
                    export PATH=/usr/lib/oracle/19.3/client64/bin:$PATH
                    export LD_LIBRARY_PATH=/usr/lib/oracle/19.3/client64/lib
                    export TNS_ADMIN=/usr/lib/oracle/19.3/client64/lib/network/admin

                    sqlplus 'username/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myrdsinstance.abcdefghij.us-west-2.rds.amazonaws.com)(PORT=1521))(CONNECT_DATA=(SID=ORCL)))' @my_sql_script.sql
                '''
            }
        }
    }
}

Here are some points you need to consider:

  • username and password should be replaced with your actual Oracle database username and password.
  • Replace myrdsinstance.abcdefghij.us-west-2.rds.amazonaws.com with the endpoint of your Oracle RDS instance, 1521 with the port number, and ORCL with the SID.
  • my_sql_script.sql is a SQL script file that you want to run on your Oracle database. This script should be present in your Jenkins workspace.
  • The PATH, LD_LIBRARY_PATH, and TNS_ADMIN environment variables are being set to locations where Oracle Instant Client is installed.

As for your question about ORACLE_HOME with RDS, Oracle RDS is a managed service, and you do not have access to the underlying file system, so ORACLE_HOME is not applicable to RDS. Instead, you connect to RDS instances over the network using the RDS endpoint, port number, and database credentials.

Keep in mind that storing credentials directly in your Jenkinsfile or any script is not a secure practice. Jenkins provides ways to store secrets securely, such as with Jenkins Credentials. It is recommended to use those for storing database username, password, or any other sensitive information.

Also, Oracle Instant Client should be installed on the same machine where the Jenkins agent is running. You can download Oracle Instant Client from the Oracle website. Ensure that the version of Oracle Instant Client is compatible with the version of your Oracle database. The installation process can vary depending on your OS.

profile picture
answered 9 months ago
profile picture
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions