This article can be used as a quick reference for setting up code release pipeline for .net based projects. Gitlab pipelines is used here , but the solution can be generalised for other CI/CD automation tools available in market
Gitlab runner is a build agent where all the build operations happen . If you are using gitlab.com for your git repositories , then configuring a runner in your VPC is a valid candidate for security sustenance
NOTE: It is a good practice to register a common group runner for all the projects in a group.
7. Register the runner with gitlab.com
PS C:\gitlab> .\gitlab-runner-windows-amd4.exe register | |
Runtime platform arch=amd4 os=windows pid=2076 revision=1b659122 version=12.8.0 | |
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): | |
https://gitlab.com/ | |
Please enter the gitlab-ci token for this runner: | |
xxxxxxxxxxxxxxxxxxxxxxx | |
Please enter the gitlab-ci description for this runner: | |
[EC2AMAZ-59OR3D8]: WIN-CI-SERVER | |
Please enter the gitlab-ci tags for this runner (comma separated): | |
WIN-CI-SERVER,WIN_CI_SERVER | |
Registering runner… succeeded runner=D5fhWHEa | |
Please enter the executor: docker, docker-windows, docker-ssh, parallels, shell, ssh, virtualbox, docker+machine, docker-ssh+machine, kubernetes, custom: | |
shell | |
Runner registered successfully. Feel free to start it, but if it’s running already the config should be automatically reloaded! | |
Setup the gitlab runner as a service | |
PS C:\gitlab> .\gitlab-runner-windows-amd4.exe install | |
PS C:\gitlab> .\gitlab-runner-windows-amd4.exe start | |
PS C:\gitlab> .\gitlab-runner-windows-amd4.exe status |
Verify Runner status on gitlab.com ( Group > Settings > CICD > Runners )
8. Install Git on this server from here.
9. Download build tools from Visual Studio Microsoft
NOTE: Installing build tools requires reboot
NOTE: Make sure to restart gitlab runner service after all the utilities are added to system path. Else changes will not be picked up by the service
Application servers also need to be configured to support remote deployment via msdeploy command . This link can be referenced as an in-depth guide .
GItlab pipelines is now ready to use registered runner for build and deployment actions.
Gitlab CICD environment variables should be used to securely inject sensitive information in pipeline.
This is a sample yaml file which can be placed in project root directory
stages: | |
– build | |
– deploy | |
build: | |
only: | |
– master | |
stage: “build“ | |
tags: | |
– WIN-CI-SERVER | |
script: | |
– nuget restore | |
– msbuild “.\dotnet-project\dotnet-project.csproj” “-p:Configuration=Release;Outdir=.\Build;DeployOnBuild=true;DeployTarget=Package” | |
artifacts: | |
paths: | |
– .\dotnet-project\Build\_PublishedWebsites\dotnet-project_Package\ | |
deploy: | |
only: | |
– master | |
stage: “deploy“ | |
when: manual | |
tags: | |
– WIN-CI-SERVER | |
script: | |
– .\dotnet-project\Build\_PublishedWebsites\dotnet-project_Package\dotnet-project.deploy.cmd /Y /M:http://172.31.1.224/MSDeployAgentService /U:$env:CI_USER_NAME /P:$env:CI_USER_PASSWORD -allowUntrusted “-setParam:name=’IIS Web Application Name’,value=’sample web site'” | |
– curl http://172.31.1.224 |
/Y can be replaced while manually testing deploy command. It runs the deploy command with -whatif flag which executed the deploy command in dry run mode/M represents the machine address where site has to be deployed .
https://172.31.1.224/MSDeployAgentService : Address when when remote agent is used
https://172.31.1.224:8172/msdeploy.axd : Address when Web deploy handler is used
NOTE: notice the username and password injection in deploy script . both are CICD environment variables added in project settings and password is masked to avoid exposing value in build logs