⬆️ ⬇️

Continuous Deployment to Windows Instance

What is the Continuous Delivery, many have probably heard repeatedly. One of the key points of this process is the build of the Build Pipeline (“pipeline” from the contractor to the customer). And for this you need to automate such processes as building the project, its deployment on the infrastructure, testing, etc. Jenkins is a great tool for such tasks.



To automate application deployment, the easiest option is to run Jenkins scripts on infrastructure hosts via ssh. But what if there was one (or several) Windows in the park from Linux instances? How to deploy to the "enemy" host - look under the cut.





To deploy on Windows as well as on Linux (well, almost), you need to install FreeSSHd and run it as a service. Next, you need to configure it through the "freeSSHd settings" window (called from the system tray). All the settings / features I will not describe, only the main ones, those that we need for remote execution of commands. On the “Users” tab, add the user “jenkins” and set the following settings:



')

On the “SSH” tab:





And on the “Authentication” tab you need to specify the path where the public keys will be stored:





Host for Deploy ready!



Now you need to generate a pair of keys on the Jenkins host and put the public part of the key in the directory on the Windows instance specified in the freeSSHd settings.

Check if we set everything up correctly (on Jenkins):

# su jenkins - $ ssh jenkins@10.1.1.160 'cmd /c dir' 


If you received a list of files, then everything is OK.



Go directly to Deploy. Create a new job in Jenkins (click on “New Job”). Then set the name and select “Build a free-style software project”. In the edit page in the “Build” section, click on “Add build step” and select “Execute shell”.

Here we will write a bash script that will take artifacts (in our case from the git repository), copy them from the Jenkins host to the Windows instance and run cmd scripts on it:



 #!/bin/bash -x REPO=/path/to/local/repo/ cd $REPO git checkout git pull origin master #copy files: lftp -u jenkins,pl sftp://10.1.1.160 <<EOF mirror -R ./ bye EOF #start daemons: ssh jenkins@10.1.1.160 'cmd /c cd \DIRECTORY && script.cmd' 




Everything is simple: the script downloads the artifacts, copies them to the Windows instance, runs the necessary cmd-scripts.



After all these actions, we have a job, which, when you click on “Build Now”, will deploy the application.



Thanks for attention! Good luck!

Source: https://habr.com/ru/post/175007/



All Articles