Jenkins - Sqlplus plugin: Cannot connect to oracle database. TNSNAMES.ORA missing - oracle

I'm making my way through jenkins but I'm stuck at the moment trying to connect to a remote oracle database in the final step of my job.
Environment vars like ORACLE_HOME and LD_LIBRARY_PATH are ok and sqlplus is running correctly. The connection string seems ok too, I endeed get connected using the same parameters through command line at the same machine, but not inside the job.
Here is the trace:
SQL*Plus: Release 12.2.0.1.0 Production
testing directory /usr/lib/oracle/12.2/client64
--------------------------------------------------------------------------
Using ORACLE_HOME =/usr/lib/oracle/12.2/client64
--------------------------------------------------------------------------
Running defined script on dweb/********#10.10.20.52:1521/*******
Temp script: /tmp/temp-script-15029865208104609348613017529755.sql
--------------------------------------------------------------------------
ORACLE_HOME = /usr/lib/oracle/12.2/client64
LD_LIBRARY_PATH = /usr/lib/oracle/12.2/client64/lib:/usr/lib/oracle/12.2/client64
java.lang.RuntimeException: TNSNAMES.ORA missing!
at org.jenkinsci.plugins.sqlplusscriptrunner.SQLPlusRunner.invoke(SQLPlusRunner.java:231)
at org.jenkinsci.plugins.sqlplusscriptrunner.SQLPlusRunner.invoke(SQLPlusRunner.java:16)
at hudson.FilePath.act(FilePath.java:998)
at hudson.FilePath.act(FilePath.java:976)
at org.jenkinsci.plugins.sqlplusscriptrunner.SQLPlusRunnerBuilder.perform(SQLPlusRunnerBuilder.java:98)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:735)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:490)
at hudson.model.Run.execute(Run.java:1735)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:405)
ERROR: TNSNAMES.ORA missing!
Finished: FAILURE
I even tried setting ORACLE_SID environment var with the same result. Any idea?
For the record: Running jenkins from a docker image

https://wiki.jenkins.io/display/JENKINS/SQLPlus+Script+Runner+Plugin
Can it be this plugin (SQLPlusRunner) only supports local naming (TNS)?
In that case, you will have to create a tnsnames.ora file placed in your favorite folder and set export TNS_ADMIN=/my/favorite/folder
cat tnsnames.ora
MY_TNS_ALIAS=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myip)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=MY_SERVICE_NAME)))
Now you can configure the connection
instance: <MY_TNS_ALIAS>
TIP: Make sure you have a succesful connection through sqlplus (CLI) before you continue with jenkins.
For your scenario, I think Oracle Runtime Client would have been a better option to install. Instantclient will work though.
Best of luck!
Bjarte

I know this is an old thread but this may benefit someone. In my case I did need to add the connection string to tnsnames.ora, but not to export TNS_ADMIN.

Related

Using DBI to connect to Oracle Database in Perl getting ERROR OCIEnvNlsCreate in Windows

In windows machine, When trying to connect to Oracle Database via Perl (strawberry-perl-5.32.0.1) getting below error.
Error:
failed: ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var or PATH (Windows) and or NLS settings, permissions, etc.
Environment variables ORACLE_HOME & PATH are correctly pointing to oracle insta client 12.2 version.
Code shown below:
my $dbh = DBI->connect('dbi:Oracle:host=hostname;service_name=servicename;port=xxx','username','password');
Issue Resolved. ORACLE_HOME needs to be set at system level environment variable rather than account level environment variable

How I configure shell sqlplus to oracle

I'm working in a new developer environment. How I set connection with oracle, because I need to execute any scripts, but I received the message: SQLPLUS NOT FOUND :/
you need to add $ORACLE_HOME/bin into your PATH. and check if $ORACLE_HOME is defined first. If it's not ,define it (just the root folder of your oracle client).
If you don't have an oracle client installed you need to install one

ORA-01031: Message 1031 not found; No message file for product=RDBMS, facility=ORA

While trying to connect to Oracle database with sqlplus / as sysdba, I get the following error:
ORA-01031: Message 1031 not found; No message file for product=RDBMS,
facility=ORA
I am using Windows environment.
How I can correct this?
Probably your oracle environment is not setup correctly. You need to set ORACLE_HOME and ORACLE_SID environment variables. ORACLE_HOME should point to the root directory of your client install.
Do you have your TNSNAMES.ORA configured also?
See here for similar issue: https://forums.oracle.com/forums/thread.jspa?threadID=619126
You almost certainly do not have read access to the directories under ORACLE_HOME.
The tool is unable to generate messages because it cannot read the files.

Oracle connectivity in Ruby

In my ruby script, I set to connect to oracle db via:
conn = OCI8.new(username, password, database)
It works well on my own desktop (Ubuntu), however, when I deploy it onto a lab machine (Ubuntu VM), it has oracle connection error. The machine has all oracle drivers needed because I can connect to it by commandline sqlplus. Also I did echo $ORACLE_HOME and it's set correctly.
The error is like:
env.c:257:in oci8lib.so: ORA-12154: TNS:could not resolve service name (OCIError)
I had the same error on my desktop when ORACLE_HOME was not set correctly. Once I set it right, it started to work. But on this lab machine, although I can launch sqlplus w/o problem, I can't connect via ruby script. Any advice?
The ORA-12154 error means that the value of the "database" argument in your OCI8.new call is not being found in the tnsnames.ora file that the environment is using. This could be due to:
an incorrect value being passed through the variable
something in the environment that is
pointing to the wrong location for
tnsnames.ora. By default it should
be in $ORACLE_HOME/network/admin, but
this can be overridden by the
TNS_ADMIN environment variable.
You say that you can launch sqlplus on the lab machine without any problem, and I assume that this means you can connect to the database of interest when you do this. If this is the case, it seems that the environment present when you run the Ruby script must be somehow different.

Oracle Pro*C ORA-12547

I'm working on re-compiling some Pro*C code that no one currently at my company has ever compiled. It's compiling OK, but when I copy it to the production server and run it I'm getting Oracle error ORA-12547 (TNS: lost contact)
Any ideas?
Oh, figured it out. :-)
The C executable isn't run directly on the server, but launched through a script that sets up the connection environment. i.e. something like this:
export SHLIB_PATH=/oracleDatabaseSidHere/oracle/10.2/lib:/usr/lib:/oracleDatabaseSidHere/oracle/10.2/odg/lib
export ORACLE_BASE=/oracleDatabaseSidHere/oracle
export ORACLE_SID=oracleDatabaseSidHere
export ORACLE_HOME=/oracleDatabaseSidHere/oracle/10.2
# Set up the path and executable to run
PATH=.\:$PATH:$ORACLE_HOME/bin:/usrlocal/bin
PATH=$PATH:/path_to_application_logs
cd /path_to_application
application
Related to this, I just found out that I get the same error ORA-12547 TNS lost contact on my Windows machine when I try to connect to an Oracle database with PL/SQL and at the same time I have a VPN connection open.
I had a similar problem on Linux, Oracle 11gR2. Oracle owner could run SQL*Plus and get in via either TNS or local connection. Non-oracle user could log in via TNS, but not as local connection.
Turns out the answer was that the ORACLE_HOME filesystem was mounted "nosuid". Removing that mount option solved my issue.

Resources