Jenkins plugin to copy files to windows server - jenkins

I have a situation where in I need to copy set of files to a windows server through Jenkins. I see a lot of Jenkins plugins that will do this kind of job through ssh but not in my case. Jenkins is also hosted in a windows server and end server is also a windows, so I believe ssh is not an option. Any plugin available in the market to get the job done or writing our requirements in powershell/MSDos script is the only option?
Thanks in advance!

just execute a bat command with the following
copy C:\localfile.bak \\remotemachine\c$\Path\remotefile.bak
in the Using the Execute Windows batch command option in the build Step
How to run bat file in jenkins

Related

How to deploy a jar on Windows server through Jenkins job?

We have a jenkins job which is getting triggered after every push to gitlab.
It creates a build. Upon successful build we want to copy the jar to some Windows server.
We are able to set SSH credentials for Linux server. How do we do it for Windows server.
Thanks
Install the slave on windows machine & trigger the .bat file through jenkine's job.

Run a db script using jenkins

I need to run a db script to take oracle database backup in a remote server using Jenkins in Windows environment. Is it possible? I created a Free style project in Jenkins and installed SQLPlus script runner plugin. But it didn't work. Can anyone please advise me how to do this?
If you have a simple shell or python script to run from jenkins then you can do it like this :
Configure jenkins job to run as shell script
and write something like
#!/bin/sh
sh <location_of_shell_script_for_backup>
You can change sh as per your requirement.

Execute Shell script from workspace on remote machine after build successful (Jenkins)

The scenario is - I have a job A which runs my ant script and packages the artifact's for me.
I am also using parametrized Triggered plug in to Trigger my "Job B" which will deploy my artifact on remote machine.
The job A is working fine and also Job B.
The tasks that i have to perform with Job B are
GIT checkout (which contains my deployment scripts) (successfully doning).
Copying artifacts from previous build to Remote machine. (successfully doing)
Run shell script on remote machine(script present in workspace folder )- Facing issues.
I browsed various plug ins for the same but no one is allowing me to run shell script after , "SCP to remote machine" which is present in Post build action.
I would like to execute the same sequence, however if you guys have any other suggestions please share.
Thanks in Advance.!
As part of Publish Over SSH Plugin, you can execute a script after the files had been copied over.
Under Post-build Actions
Add Send build artifacts over SSH
Select a preconfigured server (done in global configuration)
Select files to copy from workspace
Enter Exec command
If one of the files you copy is your shell script, you can enter it here as an "exec command"
To solve my query i used Jenkins SSH Plugin. This provides a configuration tab where i can add multiple hosts and after that used them in my job level configuration.
Link to Plugin
you get privilege to execute shell script on remote host as pre-build step or post build step.
updated the path of publish over ssh it worked for me

connect Jenkins to Microsoft SQL Server?

How can I connect Jenkins to Microsoft SQL Server?
I would like to run a script using Jenkins to update some tables in the database.
It really depends on what you really want to do. If you just want to run a script which connects to the DB and executes the queries using the command line client, you can use the existing "execute shell / batch" build step, or some of the plugins:
ssh plugin - remotely execute a script
x-shell plugin - makes it easier to integrate scripts for cross-platform envs
You could also try and build your own starting from the basics, Jenkins library plugins

continuous deployment with jenkins

I want to deploy with jenkins to the test environment and to the production environment. To do so I need to connect to the server of the wanted environment, something like ssh/scp.
I would like to know what the best way is.
I found some plugins to do this, like the Jenkins-Deploy-Plug-in or Jenkins Publish over SSH Plugin. The first has lots of issues, which is not really trustworthy to deploy to production and for the second you need to change the global configuration, which is manual work for every deploy.
Any ideas how to solve this? Maybe with some scripts or plugins?
The only current idea I have is: to connect with jenkins to a server (maybe with the SSH Plugin) and to execute there a script that connects to the wished environment. But that are two connections. Is that really neccessary? I hope for a more straightforward way for this.
thanks for any hint.
I suggest the following procedure:
one single shell script (stored somewhere on the jenkins server) does everything.
Basically, the script does scp of the build artifact and then connects to the server (ssh) and does all the necessary tasks to deploy (setup maintenance page, backup the current app, deploy the new app, ...).
On the jenkins server, there are at least 2 jobs:
the first one simply does the build (using maven, or any other build script)
the second job does the deploy : so this job only runs the shell script.
(I suggest one deploy job for each target environment : testing, production, ...)
It does not require any "special" jenkins plugin to achieve this "one click deployment".
It only requires that the jenkins user has ssh access to the target server.
EDIT
Here is a sample shell script to illustrate my post
#This script will copy the last artifact build by the job "MyApp" to test.myserver.com
#and remotely execute the deployment script.
#copy the war to the server
#(the job "MyApp" is using maven, that's why the war can be found at this location)
scp -i <HOME_DIR>/.ssh/id_dsa $HUDSON_HOME/jobs/MyApp_Build/workspace/myapp/target/myapp.war deployeruser#test.myserver.com:/tmp/
#connect to the server and execute the deployment script
ssh -i <HOME_DIR>/.ssh/id_dsa deployeruser#test.myserver.com
#The following is just an example of what a deployment script can be.
#of course you must adapt it to your needs and environment
"cd <TOMCAT_DIR>;
#first copy the current war to a backup directory (additionaly, I have a cron task deleting old undeployed apps)
cp -rf myapp-apps/myapp* undeployed/myapp-apps/;
#execute a script (stored on the server) to properly stop the app
sh bin/myapp.sh stop;
#delete current app
rm -rf myapp-apps/myapp;
rm -rf myapp-apps/myapp.war;
#copy the uploaded war in tomcat app directory
cp /tmp/myapp.war myapp-apps/;
#execute a script (stored on the server) to start the app
sh bin/myapp.sh start"
Using SSH compromises security on your environment
and is quite hard to troubleshoot.
It is better to install a Jenkins-Slave on the remote machine
and run the tests there by executing a Job on the Slave.
The Slave is monitored by the Server, which saves you a lot of trouble
managing the connection.
You can trigger the remote Job at the end of a successful build
and pass it the artifact of that build.
(can also have the first Job store the artifacts on a shared drive
and pass the location of those artifacts to the next Job).
See here:
Jenkins - Distributed builds
Jenkins - Parameterized Trigger Plugin
Jenkins - Copy Artifact Plugin
Ideally, you should be using something like Fabric or Capistrano for deployments, and call those scripts from Jenkins. I've used Capistrano extensively for both Ruby On Rails and Non-Ruby applications too. The biggest advantage I see are:
The intelligence built in to rollback the deployment in case there are errors while deployments.
Hooks it provides to run a set of scripts such as DB migration, service restarts etc.
Manual rollback in case you need to.

Resources