Adding Vagrant VM as slave in Jenkins - docker

I'm having ubuntu 16.04 as host machine.
On the top of it, there are 2 Vagrant VMs one acts as Master and another Slave.
On Master, I have Jenkins installed and running
On slave I have Docker installed. I can do Vagrant up and Vagrant ssh and run both machines at the same time.
I need to deploy a .war file which is created in Master VM on to the Docker container which runs on the slave machine. I tried to use syncedfolder option inn Vagrant and Volume in docker. I can copy the war file to webapps directory of docker container by linking those things.
But How do I add the slave Vagrant VM as a slave node in Jenkins which is running on Master VM and deploy to docker container directly from there.
Do I need to have Jenkins installed on slave VM or anything else?

But How do I add the slave Vagrant VM as a slave node in Jenkins which
is running on Master VM and deploy to docker container directly from
there.
Do I need to have Jenkins installed on slave VM or anything else?
Adding a node as a jenkins slave to the master is well documented and you can find the solution here: How to set up new Jenkins slave. Basically, the master needs only to have ssh access and it will install the jenkins slave agent on the node.
Once you have a node registered, you can scheduel builds to run on that node, where you can pretty much do anything. You will have access to all the docker commands via the shell build steps of regular FreeStyle Jobs.

Related

Running docker containers as Jenkins Slave

I have Jenkins installed on my system and I want to run docker containers as Jenkins slave.
I am confused with the configuration part of jenkins after installing docker plugin.
What should I enter in those settings?
You'll need to edit Jenkins system configuration (Jenkins > Manage > System configuration) and add a new Cloud of type "Docker"
That means you need to have docker installed in a cloud (a local one like VirtualBox, or a remote one, like Amanzon EC2.
See for instance "Using Docker as a Jenkins Cloud Provider".

How to run build on docker container in coreos?

I have installed CoreOS as my build environment. I installed Jenkins server as a docker container in CoreOS. And I created a free style project on the Jenkins server to build my project. How can I configure the build run on docker containers on the CoreOS?
So the structure is: CoreOS is my physical machine. Jenkins server is running in a docker container in the CoreOS. And I want to launch more docker containers to run my application. How can I achieve this? The hardest part I think is to launch a docker container in CoreOS from Jenkins JOB. I want to start a new docker container ever time for a build.
I'm not familiar with Jenkins, but I would suggest that you take a look at the docker-machine and docker-compose utilities.
You should be able to have Jenkins use one of those to have the host start your build container.

Deploy to JBoss from Docker Jenkins Container

I have a docker Jenkins container running on RHEL host machine that pulls out code from TFS and builds a war using Ant scripts. After the build is complete we want to push the war to a JBoss running on our RHEL host. What is the best way to do this?
We have the Jenkins home mounted to a directory on the host system and I able to manually deploy the war from this directory onto the JBoss server using the jboss-cli deploy script.
When I am inside my Jenkins container running the build can I use the file system on the host to run the jboss-cli script?
No. You can not run scripts on the host from within a container.
One solution may be to share a volume between both Jenkins and JBoss containers. This way Jenkins can deploy the war to this directory and JBoss will be able to access it.
But you cannot use the Jenkins container to run a script on the host.
If you do need to execute a script, you could link the containers (ie. add them to the same docker network). You could build the JBoss container with SSH on it, and your Jenkins job could include a step to run a command on the JBoss container via SSH.

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.

Jenkins shell script execution on different server

I have two VM, on one VM I have docker and on another I have Jenkins .I have shell script for running docker, which is placed on server which have docker on it. But I need Jenkins to execute this shell script, from pre-build step.
I am facing problem with this process.
It will be very helpful if any one can provide the detail steps
Thanks in Advance
There are different approaches to achieve that.
One is to install Jenkins slave on the VM which has docker on and have your Jenkins master run the whole job on the slave.
Or you could install one of Publish Over SSH Plugin or SSH plugin to execute commands remotely (if your docker VM has SSH access)
If your network is sufficiently secured from the outside, you could expose the docker API socket via a TCP port on your docker-machine and run the docker commands from your jenkins machine, using the remote tcp-port.
Basic idea is outlined here in the section "Bind Docker to another host/port or a Unix socket"
Cheers D

Resources