Download SQLPlus to Jenkins server - jenkins

I'm trying to run SQLPlus in a Jenkins build (I have SQLPlus installed on my local). Currently, I have a variable in my build called PATH:
PATH=/usr/local/Cellar/instantclient
My build is stable and Jenkins is able to connect to the database and execute commands. Is there a way to run SQLPlus commands on a Jenkins server that doesn't have SQLPlus installed. I'm trying to avoid using the SQLPlus script runner plug in as well.

You can install SQLPlus through the pipeline itself. For example, refer to the following. Having said that, if you have a static Jenkins instance best option is to install whatever tools that are required in the server itself.
pipeline {
agent any
stages {
stage('SetUpSQLPLus') {
steps {
echo 'Setup'
cleanWs()
sh """
curl -LO https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip
unzip instantclient-sqlplus*.zip
cd instantclient_21_6
chmod +x sqlplus
./sqlplus --version
"""
}
}
}
}

Related

Zip Command not found in Jenkins

I am trying to zip a directory in a Jenkins pipeline, my code is similar to this
stages {
stage('ZIP') {
steps {
script {
currentBuild.displayName = "DISPLAY_NAME"
}
// Zip DIRECTORY
sh '''
cd ${WORKSPACE}
zip -r zip_file_name src_dir
'''
}
}
}
I get the following error
#tmp/durable-4423e1f6/script.sh: line 3: zip: command not found
However, when I create another job with execute as a shell option for the build, zip is working fine.
I have tried using zip pipeline utillity plugin, but when I try to access the zip file it is not found.
script {
currentBuild.displayName = "${VERSION}"
zip zipFile: '${zip_file_name}', dir: 'src_dir', overwrite: true
}
#raviTeja, I guess zip utility is missing in your jenkins agent machine. What is the OS flavour of your Jenkins agent? Lets say if you are using Linux flavours like Redhat, ubuntu.. first you need to install the zip utility in the agent machine. Then alone you can use the zip command in your script
If you are using RedHat flavour in the agent machine
First install zip utility
sudo dnf install zip
Then execute zip command in your pipeline script
zip -r zip_file_name src_dir
If you are using ubuntu/debian flavour for jenkins agent
Install zip utility using apt
sudo apt install zip
Execute zip command in your pipeline script
zip -r zip_file_name src_dir
Update:
If you are using Jenkins in the docker container, you can do something similar to the below.
I am guessing you are running ubuntu base image (identify the respective base image Linux flavour and execute the below commands)
Get into docker container using exec command
docker exec -it <container> /bin/bash
Update packages
apt-get -y update
Install zip
apt-get install zip -y
But remember if you delete this container, you are going to loose this set-up. You might have repeat all these steps

how to go inside a specific directory and run commands inside it in a jenkins pipeline

I am trying to run a gradle command inside a jenkins pipeline and for that i should cd <location> where gradle files are.
I added a cd command inside my pipeline but that is not working. I did this
stage('build & SonarQube Scan') {
withSonarQubeEnv('sonarhost') {
sh 'cd $WORKSPACE/sonarqube-scanner-gradle/gradle-basic'
sh 'echo ${PWD}'
sh 'gradle tasks --all'
sh 'gradle sonarqube --debug'
}
}
But the cd is not working, I tried dir step as suggested in pipeline docs, but i want to cd inside $WORKSPACE folder.
How can i fix this?
Jenkins resets the directory after each command. So after the first sh, it goes back to the previous location. The dir command is the correct approach, but it should be used like this:
dir('') {
}
Similar to how you have used withSonarQubeEnv
Alternatively, you can simply chain all the commands
sh 'cd $WORKSPACE/sonarqube-scanner-gradle/gradle-basic & echo ${PWD} & ...'
But this is not recommended. Since this will all be in the same command, it will run fine though.

How can I run a Curl command from Jenkins A in order to trigger a build in Jenkins B

I want to trigger a build in Jenkins B by running build in Jenkins A, I know that I can use a Curl command from Jenkins A but actually I couldn't figure it how and where to write the command, inside the pipeline or as power-shell script?
Here is described how it works.
You need to download the jenkins-cli.jar from the jenkins server you want to trigger a job on.
wget http://YOUR_JENKINS_HOSTNAME/jnlpJars/jenkins-cli.jar
You have to verify that you can authenticate to the jenkins server.
ssh-keygen -t rsa && cat ~/.ssh/id_rsa.pub
Copy the public key to http://YOUR_JENKINS_HOSTNAME/user/YOUR_USERNAME/configure. On the same page you can generate a API Token. You will need it for the remote call. You can save it as file with the following command:
echo 'YOUR_USERNAME:YOUR_API_TOKEN' > jenkins_secret
Now you can call the remote jenkins server and trigger builds
java -jar ./jenkins-cli.jar -s http://YOUR_JENKINS_HOSTNAME list-jobs
To integrate it to your pipeline just add a sh step and take the last line (the jenkins-cli.jar call) and add it to your pipeline.

Batch file is not getting completely executed.

We are trying to make a Jenkins job where we will deploy our Angular app to Tomcat's webapps folder.
Our Jenkins is running on CentOS and dev server is on Windows.
We executing the following shell script in Jenkins build step.
sshpass -p "password" ssh -o StrictHostKeyChecking=no username#host "D:\Ratikanta\temp.bat"
Our batch file content is following.
d: && cd Ratikanta && svn checkout http://192.168.1.5/svn/KSP/trunk/kspweb/ && cd kspweb && npm i && npm run build && move ksp D:\Ratikanta\Tomcat7\webapps
These are working fine when running the shell script(sshpass -p ...) from CentOS terminal but, when running from Jenkins job it is executing up to npm i. Other commands like npm run build && move ksp D:\Ratikanta\Tomcat7\webapps are not getting executed.
Please help. Did we miss something? Please suggest if there are any other way to achieve our goal.

Install Python dependencies on another server using Jenkins Pipeline

Hi is there a possibility to ssh to a server activate a virtual env and install requirements from my Jenkins Pipeline Project
I have tried this but does not seem to maintain my virtual env session
node {
sh '''
ssh server virtualenv myvenv
ssh server source myvenv/bin/activate && which python "
'''
}
I found the solution you have to run it like this
ssh server "source myvenv/bin/activate; which python"

Resources