send files or execute commands over ssh - jenkins

Jenkins is running on windows machine and I am trying to copy files from windows to unix as a build step.
SSH sever details has been configured in the global configuration and connected successfully.
kindly share the Exec command to copy files from windows to unix

You need some kind of ssh client on your windows. I suggest Winscp, which is simple, easy and fast.
Winscp is a GUI application but as you want to run something from Jenkins you need to have a command line tool. Good news is that you can run Winscp in command line. Then the following steps should answer your question:
Install Winscp on the Windows machine.
Add your Winscp installation path (sth like C:\Program Files (x86)\WinSCP) to your system environment path variable
Now you should be able to run winscp command in windows command prompt
The command below will copy the file, you should read winscp manual for more details:
winscp root:password#UNIX_MACHINE_IP /command "put c:/PATH_TO_FILE_ON_WINDOWS /home/PATH_TO_TARGET_ON_UNIX"

There is a Jenkins plugin that might fit your needs:
https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin
It uses Java SSH library so no need to install another SSH client.

To copy files using PuTTY or any unix shell powered with SSH from windows, run this command.
scp /path/to/file.ext user#m192.168.0.100:/Destiny/path
To run commands in your remote computer just connect to it with:
ssh user#192.168.0.100
Customize the user, the IP and authenticate with the properly password.

Related

want to run docker file in windows machine

Team mate sent me docker file - zipped one. I want to run it in my machine. I am using windows 10 64bit machine. Do I need to unzipped file first? I am new to docker. Please suggest
Thanks
Yes, you need to unzip the Dockerfile and place it in a folder. You also need to setup Docker For Windows which can be found here: https://docs.docker.com/v17.09/docker-for-windows/install/
After setting up, start docker and use
docker build command
in the folder where you placed the Dockerfile to build the image.

Bigquery CLI commands with Jenkins

I can run a BigQuery script interactively just fine:
But when i try with Jenkins on the same windows machine it fails:
Do i need to install BigQuery SDK on the Jenkins Localhost, or tinker with some PATH varibles? :)
Make sure the directory the bq executable is installed has been added to your PATH variable (that would be the PATH_TO/google-cloud-sdk/bin directory). But this is most definitely already true given that you're able to run commands from the C drive. Different users get different permissions, so also make sure the bq command is available for the users Jenkins is operating under .
I've had the same issue where I couldn't run bq commands using systemctl on linux. To go around this error, instead of running the command with bq, use the full path to the executable PATH_TO/google-cloud-sdk/bin/bq.

How to copy file from SSH remote host to Jenkins Server. sshpass doesn't work

How to copy file from SSH remote host to Jenkins Server?
I've found one solution here:
How to copy file from SSH remote host to Jenkins Server
But when I try sshpass in Execute shell step - nothing happens. Nothing in Console output.
Can somebody advise, maybe there is some plugin for this purpose?
the reason in my case was that I had wrong paths. When I corrected paths in script, everything has just worked fine.

Using SSH in a Docker container (Windows)

Starting from the microsoft/aspnetcore docker image, I was able to install chocolatey and then use chocolatey to install some other software:
open-ssh
git
Now I want to clone a repo from our Bitbucket server:
I added the Bitbucket server to the known_hosts file (and even ssh'd into the server from the container to double-check)
I added my Bitbucket ssh key, which I've been using successfully on my machine and used successfully from an Ubuntu container
I added a config file in my user's .ssh directory to tell git to use my ssh key
I expect to be able to use git clone ssh://git#<host>/<path to repo>, but this command always fails with the following error:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository
exists.
I got this to work in an Ubuntu container with the following command:
ssh-agent sh -c 'ssh-add /home/bamboo/.ssh/id_rsa; git clone ssh://git#<host>/<path to repo>', but this command seemingly does nothing on the Windows container. I never get any feedback from ssh-agent so I am unsure if Open-SSH is even working or if there are known issues of Open-SSH in Windows containers? I do get feedback from ssh-add saying that my key was successfully added, but still I am unable to clone my git repo.
Has anybody been able to successfully do this in Windows containers? It works on my Windows machine but I'm not using Open-SSH, I'm using the Git Bash tools, which don't work in the Windows container. This is all very confusing because all the information on this topic pertains to Ubuntu containers and the resolutions all involve Unix commands that I don't have available in the Windows container.
Another strange thing I notice is that cloning using HTTP doesn't work either, instead I get the following error:
error: failed to execute prompt script (exit code 66) fatal: could not
read Password for 'http://(user)#(host)': No error
I got a little help from the Git for Windows people who suggested I use the verbose flag with the ssh command, i.e. ssh -vvvvv <host>. This showed that the config file I had in my user's .ssh directory had some extra permissions, indicated by an error message:
debug3: Bad permissions. Try removing permissions for user: S-1-5-11 on file C:\Users\ContainerAdministrator/.ssh/config
Using the icacls utility I was able to remove those permissions, which allowed the config file to be used.

Console Utility that can remote connect to other systems and issue commands

Frequenlty my work involves to VNC to a remote system and work on it. SInce i run command line apps on this remote system most of the time, i was wondering if there's an alternative software to command prompt which i could install on my local machine. Using this i should be able to create a session with the remote system and from then on all commands issued in command prompt should run in remote system.
localHost>dir --> should list the directory contents in remotehost active directory
localhost>app.exe should run app.exe in remote host and display its contents in localhost command prompt
I browsed a little and read about cmdlets in powershell. But it looks like i need to write a cmdlet for each app in the path (dir, mkdir, app.exe in the path). Correct me if am wrong. Once session is established, i simply need the commands invoked in local host to be run in the remote host and return the console output to local host. Please let me know if powershell + cmdlets are the only way
THanks
Just use PowerShell Remoting if it can be set up (requires a little preparation).
I'm not quite sure why you think of writing own cmdlets for stuff that's already there. dir is an alias to Get-ChildItem which does return the items in the current path (and—depending on options—some other stuff as well). And since PowerShell is a shell it has no problems running external programs too.
SSH is what you're looking for. Cygwin has a SSH server and client.
Unix people do this all the time with SSH. You can install the sshd server on your remote machine through Cygwin, then use PuTTY to connect to it.
As a bonus, PuTTY does not use the clunky Windows cmd.exe program; it's got a much nicer terminal of its own.
You could maybe even run PowerShell on the remote end, so you don't have to learn bash.
Depending upon on how you actuall access the machines PSExec may be an alternative that wont require you to install anything on the remote system.

Resources