GitLab CI/CD pipeline, deploy to Windows Server - gitlab

Using GitLab Runner I have on Linux, I am trying to connect to a Windows Server and run some basic commands there such as git pull.
Does GitLab runner provide any capabilities for accessing windows server?
What other options are there to get such requirement done?

I think you have a few options
install openssh and configure server on your windows machine/vm and connect from your gitlab runner with ssh ( https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse )
( as Wojciech Wirzbicki commented) install a gitlab runner instance on windows. https://docs.gitlab.com/runner/install/windows.html . I think this option more secure and easy win
connect to windows server with winrm

Related

How to deploy my Node server to ec2 using Jenkins?

I have probably been Googling this the wrong way...
I have a Node express server.
I want to deploy it using Jenkins to ec2.
What are my options?
if I want to upload the code manually, I use ssh... but I want it to
be done from Jenkins.
Yes the server is on a git repo.
I would like a devops flow
I recommend you , to do it step by step :
Step 1 : Configure correctly a jenkins job ready to build your app in remote ec2 machine.
Install this plugin in your jenkins platform : Publish Over SSH Plugin
Using this plugin add new remote server under Publish over SSH section in Manage Jenkins >> Configure System option.
Now create some jenkins job. Then, in build section add a step called : Send files or execute commands over SSH
Just select your configured server and enter your commands in Exec command section :
For a simple node js express, this code could be enough or just copy-paste your existing code:
https://gist.github.com/jrichardsz/38b335f6a5dc8c67a386fd5fb3c6200e
That is all. Just test with "build" option and verify if your application goes well.
At this point, this job is functional. The flow could be :
push your changes to your git provider
login to jenkins and manually execute the created job (this step is replaced with webhook configuration)
Note: If and only if this step has no errors, you can start with the following step.
Step 2 : Implement a simple devops flow by configuring a webhook in your git provider, which automatically triggers the jenkins job (create in step 1) when you perform a git push.
This guide could be help you with the required configurations :
https://jrichardsz.github.io/devops/devops-with-git-and-jenkins-using-webhooks
You'll have to use AWS CodeDeploy jenkins plugin. This apply to any type of code. Node, java etc
See AWS article
Setting Up the Jenkins Plugin for AWS CodeDeploy
Jenkins Plugin
Github Link

Running Giltab-runner on multiple servers

It's possible to use gitlab on one host and Gitlab-runner on other host. For example , I have ansible server on other host and I want to setup there gitlab-runner
Yes.
From the documentation:
Ideally, the GitLab Runner should not be installed on the same machine
as GitLab. Read the requirements documentation for more information.

How to connect to remote deployment windows server in Jenkins Pipeline script?

I am using Jenkins Pipeline to set the build and deployment process. For the build, i am using a Windows server node but for deployment, I have to use separate deployment servers (Windows machines) for Dev, QA and Production environments which cannot be added as slave nodes. I have to connect to these deployment servers to execute the deployment code. I have already tried using PowerShell and PSExec to connect to the remote machines and both are working fine, but our requirement is not to use any of these (PowerShell or PSExec) and do everything in Groovy scripting. I have searched everywhere but have not found a suitable solution to connect to the remote windows servers using Groovy in Jenkins Pipeline and run the deployment commands. Please suggest.

Executing node.js script remotely

I am setting continuous integration using Jenkins server for my Node.js application. For deployment I am using a powershell script and for that I have installed powershell plug-in. The script will need to perform the following tasks in the order.
# Step1
# Stop all the currently running services on web server. For that I am trying to
# execute maintenance.js remotely from the build server under node
node \\SharedWebServerFolder\Utilities\maintenance.js stopServices
# Step2
# Copies all the resources to server at \\SharedServerWebFolder
# Step3
# Start the services
node \\SharedWebServerFolder\Utilities\maintenance.js startServices
I have no problem executing Step2. My question is about Step1 and Step3.
Should I execute maintenance.js remotely from the build server? Is this even possible? ( Assume I have installed node.js on the build server)
Should I have one more PowerShell script on the web server which executes maintenance.js locally? So basically deployment script (from build server) will execute remote PowerShell script (which is on web server) and that remote PowerShell script will execute maintenance.js locally. In this scenario I don't have to install Node.js on the build server.
What is recommended?
People generally use ssh to execute commands remotely. I think you want to execute a command from your build server on your production / staging server.
see linux execute command remotely
this is simple where the remote box is a linux box.
If your remote is a Windows box then you can still run an ssh server on it but its more painful to setup. you might try Bitvise SSH Client.
Once your ssh client is setup correctly you should be able to execute remote commands from your build server.
I have used Jenkins SSH Plugin for deployment in my remote staging/production servers.I would recommend to execute your 'maintenance.js' in web server machine instead of your build server.You can just trigger 'maintenance.js' execution in staging/production servers from build server using ssh.I believe the execution of 'maintenance.js' remotely from the build server is hard to achieve.

GitLab-CI Multi Runner can't fetch gitlab repo and returns http error

I am using Gitlab-CI-Multi-Runner on Windows (64 bit), and have configured it to run with the default shell. The connectivity with the Gitlab server is fine, but when it tries to run a build, it is cloning the repository using HTTP endpoint. My repo is quite big, and the Gitlab NGINX fails with an error. SSH endpoint works perfectly.
How do I make my GitLab-CI-Multi-Runner use the SSH endpoint when cloning the repo for executing a build?
Note: The same problem existed with the older Gitlab-CI-Runner for Windows which was written using C#.
The problem is related to the timeout of the unicorn engine workers, that is too short to allow big repositories to be cloned/pushed.
in /etc/gitlab/gitlab.rb uncomment and set
unicorn['worker_timeout'] = 1200
(hopefully enough).
then issue
# gitlab-ctl reconfigure
# gitlab-ctl restart
that works for me.

Resources