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.
Related
I have a Gitlab server from the company where the project and the pipeline are configured. By default, every time a commit is done, the pipeline starts to execute in the Gitlab server.
I have my personalized VM, which is completely different from Gitlab. I want that the pipeline will be executed in my personalized VM instead of the Gitlab server. What should I do so that the pipeline runs on the VM and not on the Gitlab server?
I have configured the following runner in config.toml that is located in $MYPROJECT/:
[[runners]]
name = "Project-name"
url = "https://gitlab.server/"
token = "TOKEN ID"
executor = "shell"
shell = "bash"
There are things that I don't understand.
If I want to execute the pipeline in my personalized VM, should I install Gitlab runner in the VM [1]?
Should I have the project source code in the VM so that it can read the config.toml file every time there is a commit?
If I register the runner with the token key in the Gitlab server, how the Gitlab server knows that the pipeline is to be executed in the VM and not in the server [2]?
Should I use the executor docker or shell, to execute the pipeline in the VM?
[1] https://docs.gitlab.com/runner/install/linux-manually.html
[2] https://docs.gitlab.com/runner/register/#registering-runners
For running a job on a machine you need a GitLab Runner installed on that machine, connected with the GitLab server.
The project source code is fetched automatically in front of every run
You can use a tag (e.g. "MyVM") when registering the runner. Then you can set the same tag into your job so that this job is only executed by this runner. See: https://docs.gitlab.com/ee/ci/runners/configure_runners.html#use-tags-to-control-which-jobs-a-runner-can-run
You need to use docker if you want to use docker in your VM (which needs to be installed before there). Otherwise use shell.
Actual i have installed a self hosted agent on my local machine
now my issue is when i am running a release pipeline for a client machine i have a powershell task in which i have a command that runs an exe file located in client machine which displays a message box .
but when I am checking at client machine i am able to see the exe is running in task Manger during the execution of my release pipeline but show how i am not able to see the interface of the application .
You can try adding -Wait to your powershell command. For below example.
Start-Process -FilePath "path to programm.exe" -Wait
You also need to make sure the deployment agent(the agent installed on client machine) is running in interactive mode.
To configure the agent in deployment group to run in interative mode. You need to change the Registration script you copied in azure devops. Remove --runasservice when you run the registration script on the client machine
Then you will be asked to set the agent to run as service or not as below screenshot(Please enter or type N to select interative mode) during the setup.
Check Interactive vs. service for more information.
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
I have a build pipeline running on Windows that I cannot move to Linux, the simple reason being that it uses SQL Server tools not currently available on the RC1 version of SQL Server on Linux. Therefore my only option for running my build pipeline which needs to spin up SQL Server in containers on a Linux machine is to keep Jenkins on windows. My question is this, what is the most elegant way of creating a container on a remote Linux host from a windows server ?. I could use remote shells, however this seems like a really clunky way of doing things.
You can do this by installing a slave of the Jenkins (that is installed in Windows host) on your Linux machine and execute a job which will bring up a SQL container.
Since you are using a Pipeline job and want to execute few steps in the master and then call the SQL packages in remote hosts from your Windows host you can follow the below syntax to achieve that in a single pipeline job:
node('master') {
...................
<some task to perform>
...................
}
node('slave1 && slave2') {
...................
<some task to perform>
...................
}
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.