How Do You Get Jenkins 2.x Running on Linux to Do Code Deployments to Windows Servers?

Problem scenario
You are trying to set up a CI/CD pipeline in your heterogeneous enterprise server network.  You want to push down files (integrate code) from your Jenkins 2.x server running on Linux to your Windows 2016 Servers.  How do you get builds to be controlled by Jenkins on Linux to be deployed to other Windows servers?

Prerequisites
This solution assumes that Jenkins is running on Linux.  If you have Debian Linux, see this posting.  If you have Ubuntu Linux, see this posting.

Solution
1.  Install cygwin on the Windows server so it is ready for SSH.  If you do not know how to do this, see this posting.  Cygwin is covered under the GNU General Public License.   

2.  On the Linux server run this:  sudo su jenkins

3.  Set up SSH with the Windows server so that the Jenkins user can passwordlessly connect to the Windows server.  If you do not know how to configure passwordless SSH, see this posting and prepare the Windows server for SSH via its Cygwin command prompt application.

4.  On the Linux server run these commands:

cd /home
mkdir jenkins
sudo chown jenkins jenkins
sudo chgrp jenkins jenkins
cd jenkins
mkdir .ssh
chmod 700 .ssh

5.  Create an authorized_keys file in the .ssh directory.  The content should be that of an id_rsa.pub file.  This id_rsa.pub file should belong to a local user of the server you want to SSH into (e.g., a Windows server with Cygwin on it).  This content should become the basis of the authorized_keys file to reside in the .ssh directory from the above step.

6.  Run these commands from the .ssh directory in step #4:

sudo chmod 600 authorized_keys
sudo chown jenkins authorized_keys
sudo chgrp jenkins authorized_keys

7.  Go to the Jenkins web UI and log in.

8.  Go to "New Item" and enter a name.  Then click "Freestyle project."  Then click "Ok."

9.  Go to "Add build step" -> "Execute Shell". 

10.  Insert a command such as this (where jdoe is the user and x.x.x.x is the IP address of the Windows server):

scp /tmp/basic.txt jdoe@x.x.x.x:/home/jdoe/basic.txt

11.  Click "Save."

12.  Schedule the build or choose the option to "Build now."

Leave a comment

Your email address will not be published.