How to send build artifacts over ssh using Jenkins pipeline - jenkins

I was using Freestyle project method for configuring jobs in Jenkins. I have used Publish Over SSH plugin to send war file to remote system. Now i moved to pipeline configuration. I would like to know how can i do the same in pipeline configuration. Can anyone tell how to write pipeline script for publish over ssh?
Any help would be greatly appreciated.

You can use the raw Unix command scp, as described there : Example syntax for SCP. scp is Unix utility for secure copy... over SSH, which is exactly what Publish Over SSH uses behind the scenes !
Example :
scp your_username#remotehost.edu:foobar.txt /some/local/directory

Related

Jenkins SSH remote script output

I am running several remote ssh scripts on machines using jenkins. I would like to get some of the output of the runtime to parse back/process on the jenkins machine/other machine. Is there an easy way to do it, or I need to write to a centralised storage?
Thanks

How to place an artifact in a remote server and unzip

Hi have requirement to Continous deployment using Jenkins and below are the steps to achieve.
1.Jenkins job download the artifact from Nexus and place it in a remote server
2.Unzip the artifact present in the remote server.
3.Perform Gradle task in remote server
You could try using Ansible maybe https://docs.ansible.com/ansible/latest/modules/copy_module.html
If it is Windows:
https://docs.ansible.com/ansible/latest/modules/win_unzip_module.html
You have modules for every situation:
https://docs.ansible.com/ansible/latest/modules/modules_by_category.html
You could do it with Jenkins, scripting the code, and probably storing the login in the Jenkins credentials.

How to automatically copy artefacts from Jenkins job into given network drive?

I'd like the files generated by Jenkins script to be automatically copied into a given directory on the local network.
Is there a plugin or script for doing that ?
In my case it worked by using SCP in a build step "Execute shell". The remote server needs to be accessible via ssh.
If your artifacts are the result of a maven build, maybe a Nexus Repository Manager is what you are looking for. A simple mvn deploy would do the job.

Jenkins plugin to copy files to windows server

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

Jenkins Pipeline file

I am in the process of writing a declarative jenkinsfile to build a pipeline project. Some of the steps within a few of the stages will require some remote commands to be run. The remote ssh sites have been configured in the main jenkins configuration.
How can I declare these steps within my jenkinsfile? I know I can run shell commands locally using sh but it's the remote servers that i need to know about?
You need to install ssh-agent plugin then you will be able to execute remote commands using ssh. Check this for examples

Resources