Running sql script in Jenkins using SQLcl - jenkins

I am newbie in Jenkins and I would like to use Oracle SQLcl to run sql query before starting the job.
Earlier I planned to use SQLPlus Script Runner but it requires additional software(Oracle SQL*Plus) and I cannot install it on the machine.
Oracle SQLcl doesn't need anything more so I think it can be solution.
Is it possible to run sql query using SQLcl in "Execute Windows batch command" textbox ? (or execute command to run sql script from the file)
Or maybe I can do this by using "Execute shell" ?
So far I did:
In the "Execute Windows batch" textbox I typed:
cd .\sqlcl\bin
sql userName/passw#//test_database_address:port
#test.sql
test.sql contains simple simple sql query.
After running my Jenkins job I see:
Connected to: Oracle Database ...
Disconnected from Oracle Database ...
\sqlcl\bin> exit 0

Related

Can Jenkins run some code or it is only scheduling external programs?

I'm new to Jenkins and I heard it is really good for continues integration.
My flow is not complicated: I need to get a list from SQL by some query, parse it line by line, send each line to some virtual machines (which will run this line and create some file as result), and then analyze the results.
Where in Jenkins can I program my code?
Is Jenkins' purpose is only to schedule external programs one by one and not to run the code in Jenkins itself?
Is there a way to write code in jenkins that is not a bunch of CMD commands?
you can do the following ( syntaxic pipline ) :
- stage 1 : execute command over ssh (jenkins plugin) to execute sql query
- stage 2 : send each line to dedicated VM with Ansible playbook
- stage 3 : analyze depend on the tech you are using there are plenty of jenkins plugin to connect to monitoring and analyzing tools like grafana or zabbix .. that can ease the process
I think what you are asking for is scripted pipeline: https://jenkins.io/doc/book/pipeline/
This allows you to write Groovy code to execute on the Jenkins master. You can do almost anything you want from there, just like any programming language.

How to set a task variable from a remote powershell script?

From a release definition,
When I execute the following powershell script with the powershell task, it works
successfully and I can retrieve the value from the following tasks in the release definition :
Write-Host "##vso[task.setvariable variable=sslThumbprint]toto"
When I execute the exact same script thanks to the "Powershell on target machine task", I don't get any value.
How can I set a variable from a powershell script that do not execute on the agent machine ?
Regards,
This can only be done in case of hosted agents. If you are using hosted agents then only you will be able to run the commands on the agent's machine.
Microsoft as of now provides no feature for doing this.

In jenkins, execute shell command based on test result

I want to execute a shell command using
jenkins
based on test result. that means,
if the test result is successfull, i will execute the shell script and if not, i quit.
which plugin i have to use???
please save my searching time by giving ur suggestion.

Is there any way to start appium server silently?

Use case: I need to start appium server on CI Jenkins and run tests right after that. Tests don't start because appium server starting in debug mode and doesn't switch to another command.
So i have jenkins on Windows machine with the following build steps (as Windows batch command):
start /B node path_to_appium_server\appium.js --address 127.0.0.1 --port 4723
timeout 10
"path_to_tests_runner\vstest.console.exe" "path_to_dll\test.dll"
And in this case, my tests cannot started because jenkins terminate first process (with appium).
Basic issue was with permissions for '*.dll' file which contains tests and which cannot be ran with bat file without 'runas' command (which is waiting for password) from Jenkins.
So my Jenkins job contains 3 Build steps:
execute Windows batch command
start node path_to_appium_server\appium.js --address 127.0.0.1 --port 4723
Run unit tests with VSTest.console (to get this build option you need install VSTest Runner plugin)
specify path to dll and command line parameters
execute Windows batch command
taskkill /F /IM node.exe
Second step resolve permission issue for dll file.
It depends on how are you starting it. In most situations if on Jenkins you have 2 ways:
Start appium and tests in different build "shell execution" steps
If you want to do it in the same build step, just start it in a background with "START /B program".
Requirement
Installed Node.js 0.10 or greater.
At least an appium server instance installed via npm.
using javaclient 3.2.0
AppiumDriverLocalService service =AppiumDriverLocalService.buildDefaultService();
service.start();
service.stop();

Can't access build parameters in excute shell in jenkins

I'm trying to call a python script through an execute shell step in a Jenkins parametrized build. The problem is I need to pass the build parameters to the python script which doesn't happen. Here is how I call the python script in execute shell:
python2.7 C:\test\my_script.py -m $module
$module is passed as an empty string.
I've tried in Execute Windows batch command with %module% and it worked fine.
But I need to run it on an excute shell not a windows batch command.
It looks like you are running on Windows ("C:\test\my_script.py ..."), so "Execute shell" will not work properly.
Should either use Execute Windows batch command or move your job to a Unix/Linux machine (can use a Jenkins-Agent for that).
Try this
python2.7 C:\test\my_script.py -m $MODULE
From the documentation
Note that because of the case sensitivity difference of environment
variables in Windows and Unix, all the environment variables added by
parameters are in upper case.
Hence please try using $MODULE instead of $module

Resources