Configure ssh for Jenkins inside Docker - docker

i have a jenkins that run inside a docker container (on a server A) and i want to publish an artifact over ssh in a server B.
I have installed the plugin "publish over ssh" in Jenkins but i don't know how to configure the ssh.
I guess that i must generate a public/private key on the server A and send my public key on the server B. But for which user?
I have a user jenkins on the server B but not on the server A. Should i generate the key with the same user that run the docker on the server A? Where should I put my keys?
Thanks.

Related

Ssh from docker container running as gitlab runner

I got a weird problem. I am using a docker contdainer runner with Gitlab ce to do our builds anywhere. One thing I need to do is to Scp results to a central server. The user id, private and public keys are the same on the remote server as the container and I have the remote server as a known host and the public key in the authorised keys file on the server.
Now if I spin up this container stand alone, I can ssh to the remote server. However, when I’m running as a docker container runner on gitlab, it can’t see the remote server.
I know I’m missing something simple but can’t figure it out.
Anyone have any ideas?
So this turned out to be a sync problem where we pass the ssh keys in to gitlab via variables and write them into ~/.ssh
We have a a group set of variables on gitlab and a project one, which had older keys and thats what caused ssh to fail.

How to create a VM jenkins with url to access remotely from outside

I am having Jenkins in my virtual machine Azure .i need to access it with URL remotely from outside.
No matter which the steps you have done, create the VM with a cloud-init file to install the Jenkins, or create the VM and then install the Jenkins. There is no difference.
You need to open port 8080 for Jenkins traffic and port 1337 for the Node.js app. If you finish all the settings of Jenkins, then you can browse the Jenkins with the VM public IP and the port 8080 outside the VM, the URL like this: http://vmPublicIps:8080. Get all the steps from Create a VM in Azure with Jenkins.
Or you can just create a Jenkins Server with the image that Azure provided, see Create a Jenkins server on an Azure Linux VM from the Azure portal.

Making docker container a build executor for jenkins

I have a ec2 instance running as my jenkins master. I would like to run a container in that instance that will be used as another build executor so I can tun a few builds simultaneously.
Im having pronblems connecting these.
In the docker hub jenkins docs it says under the relevant section:
You can run builds on the master out of the box.
But if you want to attach build slave servers through JNLP (Java Web
Start): make sure you map the port: -p 50000:50000 - which will be
used when you connect a slave agent.
If you are only using SSH slaves, then you do NOT need to put that
port mapping.
but when I try to add a node in the jenkins config, it asks remote root directory (probably should be /var/jenkins ? ) and a launch method.
I don't quite understand what I should give it as its launch method to make this work and I don't understand where the port number comes into play.
What you need is Jenkins Docker plugin (link below) and follow the instructions listed here
https://wiki.jenkins.io/display/JENKINS/Docker+Plugin
I followed those instructions and was able to setup dynamic slaves in Jenkins which are dynamically provisioned.

How to get ssh public keys of a Jenkins master in a docker container

We followed Jenkins's official guide and our master is running as a docker container. I'm now trying to set up another machine as slave for this Jenkins master and I think I need to manually copy the public SSH keys of the master to the new slave machine. How do I access these keys? Isn't it a problem that the Jenkins container that can be destroyed and created many times? It does have a persistent volume container for jenkins data but I'm assuming that's not where the keys are.

How to work on remote machine from jenkins without adding as a slave or How to add slave through url?

I have to run some jobs from a website.
Jenkins is the best solution for it.
But we have to run the jobs on the users machine with the users id.
For this we need to add users linux machine as slave or Is there any plugin through which we can do ssh on users machine and do all the processes?
I thought of using swarm plugin but swarm dependencies jar need to be run from the user's machine. Again we need to do ssh on user's machine to run the jar.
See the SSH plugin:
This Plugin was derived from the very cool SCP Plugin.
You can use the SSH Plugin to run shell commands on a remote machine via ssh.

Resources