Connect to RDS database

0

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

1개 답변
1
수락된 답변

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
답변함 9달 전
profile picture
전문가
검토됨 2일 전
profile picture
전문가
검토됨 9달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠