Jenkins container: Groovy script fails with jbdc exception - oracle

I have a job in Jenkins (Jenkins is running from a container) which uses a groovy script with the line:
import groovy.sql.Sql;
def driver = "oracle.jdbc.pool.OracleDataSource"
when running it, I'm getting the exception:
java.lang.ClassNotFoundException: oracle.jdbc.pool.OracleDataSource
I know what is the root cause, but don't know how to fix it.
The root cause is that all our Jenkins containers are installed without Oracle, and ojdbc7.jar can be found in the java classpath under Oracle:
classpath /oravl01/oracle/12.1.0.1/jdbc/lib/ojdbc7.jar
in regular Jenkins server, it runs without any issues.
any idea how to fix it?

I did 2 things:
1. copied the file ojdbc7.jar to the path mentioned in java.ext.dirs (in illinXXX:XXX/systemInfo)
2. Ran the docker run command with --env classpath=[path of ojdbc7-12.1.0.2.jar]

Related

Issue in jmeter with adopopenjdk 8

I am trying to execute one jar having few parameter as well in apache-jmeter-5.1.1. I am running Thread Plan -> OS Process Sampler. But getting below error always :
Response message: Exception occurred whilst executing system call: java.io.IOException: Cannot run program "java -jar /User/wasim/Desktop/My_Jar/RunTask.jar " (in directory "/User/wasim/Desktop/jMeter/apache-jmeter-5.1.1/bin"): error=2, No such file or directory
I tried to run jar directly and with full path.
I have passed java_home as parameter as well.
This is the request in jmeter interface :
Working Directory: /User/wasim/Desktop/jMeter/apache-jmeter-5.1.1/bin
Environment: {JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home}
Executing: java -jar /User/wasim/Desktop/My_Jar/RunTask.jar update 20180401
i solved the issue after doing below changes :
In command section put only "java"
then put all your command after java into Command parameter section like below :
-jar
RunTask.jar
update
20180401
Make sure all remaining command should be in separate line without any space in the end.
Happy learning.

Tomcat startup script not working when invoked from jenkins

There are two tomcat instances. One for jenkins(tomcat8-jenkins) and one for the application(tomcat-mc). They are in the same server.
When I execute the shell script in build setup from jenkins it seems like the jenkins is trying to start it's own tomcat instance. following is the script and the error.
cd $TOMCAT_PATH/bin
./shutdown.sh
./startup.sh
ERROR
+ cd /usr/local/tomcat-mc/bin
+ ./shutdown.sh
java.lang.ClassNotFoundException: org.apache.catalina.startup.Catalina
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:216)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:391)
+ ./startup.sh
PID file (/usr/local/tomcat8-jenkins/logs/tomcat.pid) found. Is Tomcat still running? Start aborted.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I've tried unsettling BUILD_ID= and changing CATALINA_HOME=$TOMCAT_PATH . But still the error comes.
This might be helpful to you..
https://stackoverflow.com/a/28938556/4595123
The reason here was jenkins tomcat has set the CATALINA_BASE. After resetting that to desired tomcat base issue was resolved. Hope it may help somebody in need.
In my case added this to build shell script in jenkins which overides the jenkins tomcat CATALINA_BASE
export CATALINA_BASE=/usr/local/tomcat-mc

MacOS Automator impact maven on Jenkins job

We have macOS machine as a slave for Jenkins.
All code are executed on macOS machine.
After restarting macOS I have to reconnect slave manually.
So I created created a app with Automator and put it into lauch applications after login for my user.
Automator app is ash script like:
java -jar /selenium/slave.jar -jnlpUrl
http://1.2.3.4:4444/computer/macOS/slave-agent.jnlp -secret
0b149c641804f1424dsd998980sasd90asd8as73baa9f3f21c21e06d7681a6f6876ed
When I restart macOS the slave get up automatically,
BUT now I start getting build failures. Jenkins could not identify Maven anymore:
00:41:29 + mvn -v
00:41:29 /var/folders/88/6yf63sjn4r9_lzfld6m22fr80000gq/T/hudson5948404320742882477.sh: line 13: mvn: command not found
Looking forward for any comments on this.
Thanks.
Your shell script is excuted as different process which doesn't have all the correct environment properties setup.
You definitely need to add maven path to the PATH variable, and probably a bunch of others, into your script.
Example
export PATH=/usr/local/bin/mvn:$PATH
java -jar /selenium/slave.jar -jnlpUrl http://1.2.3.4:4444/computer/macOS/slave-agent.jnlp -secret 0b149c641804f1424dsd998980sasd90asd8as73baa9f3f21c21e06d7681a6f6876ed

Unable to delete pom.xml in Jenkins under Tomcat/Windows

I've been struggling with an annoying "Jenkins/Tomcat/Windows" problem for a while now without reaching any solution.
I've installed Tomcat version 7.0.25 in a Windows 7 Enterprise machine and Jenkins 1.451 as a webapplication
running under Tomcat. I have just 4 jobs configured right now and all of then are using the "Always chekout a fresh copy" checkout strategy,
so everytime a job runs the content in /jobs//workspace gets deleted. But, there are situations in which the job fails to run because
it is unable to delete the /jobs//workspace/pom.xml file like you can see in this (edited) stacktrace:
Building in workspace C:\.hudson\jobs\<task name>\workspace
Cleaning local Directory .
java.io.IOException: Unable to delete C:\.hudson\jobs\<task name>\workspace\.\pom.xml
at hudson.Util.deleteFile(Util.java:237)
at hudson.Util.deleteRecursive(Util.java:287)
at hudson.Util.deleteContentsRecursive(Util.java:198)
at hudson.scm.subversion.CheckoutUpdater$1.perform(CheckoutUpdater.java:73)
at hudson.scm.subversion.WorkspaceUpdater$UpdateTask.delegateTo(WorkspaceUpdater.java:136)
at hudson.scm.SubversionSCM$CheckOutTask.perform(SubversionSCM.java:780)
at hudson.scm.SubversionSCM$CheckOutTask.invoke(SubversionSCM.java:761)
at hudson.scm.SubversionSCM$CheckOutTask.invoke(SubversionSCM.java:745)
at hudson.FilePath.act(FilePath.java:788)
at hudson.FilePath.act(FilePath.java:770)
at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:735)
at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:677)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1195)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:576)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:465)
at hudson.model.Run.run(Run.java:1409)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:481)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:238)
Retrying after 10 seconds
Here you can see Tomcat locking the file as I told:
After some time Jenkins/Tomcat releases the lock on the pom.xml and i can execute the job again without any problem.
Does anyone know how to get around this ? Am i missing something ? Thanks in advance!
I changed to Windows Service installation, and the pom.xml never gets locked anymore.
Seems that this caused by Tomcat that somehow locks the pom.xml, although the build has finished.

auto start stop remote tomcat before redeploying war by jenkins (deploy plugin)

at the moment jenkins build my project and at the end the artifact is deployed on a remote tomcat via jenkins deploy plugin.
the problem is that after several redeployments this process fails (sometimes tomcat hangs or (un)deployment fails). in all cases stopping tomcat and manually undeploying helps.
Is there a way to stop tomcat before building/deploying, delete the old war and appfolder, and restart tomcat before deploy plugin wants to deploy the artifact?
thx in advance
You could write a batch file that does all the things mentioned:
stop tomcat
delete war files
start tomcat again
Then you can add a new pre/post build task in job configuration as execute batch and simply point it to run your batch file.
Added:
You can use PsExec - http://technet.microsoft.com/en-us/sysinternals/bb897553 It allows you to run processes remotely. Put batch on remote machine and from local one using Jenkins run sth like this: PsExec.exe \xx.xx.x.x C:\MyScript.bat
one addition to accepted answer:
it is important to reroute the output and error output of PsExec call (took me 2 days of debugging). See http://jenkins.361315.n4.nabble.com/remotely-executing-commands-td3476417.html
it seems that if called from java (like jenkins/tomcat) or .net PsExec hangs or quits with error. so the call should look like:
c:\someBatchWithPsExec.bat >>log.txt>&1
or explicitly on every call:
PsExec.exe -u [domain\remoteuser] -p [password] /accepteula \remoteMachine net [stop|start] Tomcat7 >>log.txt>&1
i guess if jenkins runs with domain\user u don't have to mention it in command?! (just tried it but it didn't work - the net commands fail)

Resources