Pull file/dir from remote machine Jenkins plugin - jenkins

I want to pull file or directory from a remote linux machine to Jenkins machine. Is there any Jenikns plugin available?
I am using one plugin "Publish Over SSH" and I am able to transfer files but not receive. I don't want to write/expose password to scp command line. Please suggest a way.

probably you're looking for this https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin

You may not need to expose the credentials in the script. You can manage those in jenkins and pass them as parameters which can be hidden in log. Refer the links below.
https://wiki.cloudbees.com/bin/view/Jenkins+Enterprise/InjectingSecrets
https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin

Related

Deploying configuration via Jenkinsfile to unknown amount of servers

We're setting up multiple more or less static servers in AWS. These are primarily configured via Ansible and that's also the ultimate source of truth when it comes to their existence, grouping, host names and IPs. But then there's Jenkins deploying configuration files to these servers based on new commits added to a git repository.
I'm having an issue with listing the target servers directly in a Jenkinsfile. How shall I proceed? Which are the most common ways of dealing with this?
I understand this is mostly an opinion based topic. But maybe there's a particular Jenkins feature which I don't know about...?
Thank you.
This is very subjective. Following are a few ways to do this.
Store the details somewhere accessible after the Ansible step. Possibly commit to a Github repo and retrieve these details within the Jenkins Job.
Using AWS APIs/CLI to retrieve server details. You can either set up AWS CLI in Jenkins Agent or use something like AWS Step Plugin.
Do an API call to Jenkins after the Ansible script is executed and update the server details in the Job itself.

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 send build artifacts over ssh using Jenkins pipeline

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

jenkins (Publish with SSH Plugin)

I want to build my maven project in Jenkins and copy all the the jar files to a remote Unix machine.
Also I want to connect to a LDAP data Store and start the services and test if the services are up and running
Basically I want to do the following tasks after my project is successfully build in Jenkins:-
1)Copy current version of my project to designated machine and location
2)Copy configure to connect to a designated integration test DS
3)Start the services in my project
4)Test that it is running.
Can I achieve this by Publish over SSH plugin provided in jenkins??
Or Shall I create some scripts which can automate the above tasks.The reason I am asking this is because I am not very familiar with Jenkins and Unix scripting.
Is there any good approach to do this task.
Thanks in advance.
Ansia
The Publish over SSH plugin will allow you copy files to remote server and execute arbitrary commands on the remote server.
Question is - do you know how you would achieve the following on the remote server?
2)Copy configure to connect to a designated integration test DS
3)Start the services in my project
4)Test that it is running
If yes, just enter those commands into Publish over SSH configuration. Or provide a script to be executed.
If you don't know how to achieve that, then that's a separate question.
Yes, you can use the publish over ssh plugin to copy the jars, and execute a script which launches your services. Take a look here to see how to launch a script "in the background" so it does not get killed when the session ends or to avoid blocking the Jenkins build by making it wait for the script to finish executing
Can't say much about LDAP as I haven't used it but depending on your needs I guess you could create a basic helper-jar with spring-ldap or any other similar library.

Setup Jenkins to monitor external job

I read the part of the Jenkins wiki that covers setting up a remote job to be monitored by a Jenkins instance. However, the documentation is confusing as it doesn't tell me what to configure on the Jenkins machine or the remote machine (the one that does the job).
Further, the documentation mentions Java commands that can be fired directly and others that need a servlet container. Do I have to install a servlet container on the remote machine?
Maybe it's all there but for me it's like a mix of two documentations. Can you please clarify:
What do I need to do on the remote machine?
What do I need to do on the Jenkins machine?
Thank you.
In Jenkins, you need to create a job using the "Monitor an external job" option. Give this a name, for example "nightly-backup".
On the machine where the external job is running, you need Java installed and some basic Jenkins JAR files, so that the job results can be sent to Jenkins.
As the wiki page says, on some versions of Debian or Ubuntu you can do this with:
sudo apt-get install jenkins-external-tool-monitor
Otherwise, you have to copy a bunch of JARs manually — i.e. those listed on the wiki page — to your remote machine.
Once you have the JARs available on your remote machine, you can execute whichever command you like there, so long as you prefix it with some Jenkins information: where to find the Jenkins installation, the main Java JAR, and the job name:
JENKINS_HOME=http://my-jenkins/ java -jar jenkins-core-*.jar nightly-backup ./backup.sh --nightly /home
Where http://my-jenkins/ is the base URL to Jenkins, nightly-backup matches the name of the "Monitor an external job" you created in Jenkins, and ./backup.sh --nightly /home is the command you wish to run.
The output of this ./backup.sh command will show up in Jenkins automatically once it's complete.
It looks like this is now called "jenkins-external-job-monitor", so you'd type:
sudo apt-get install jenkins-external-job-monitor

Resources