.NET is one of the important frameworks used in the web development services. In this blog, we will try to cover the end-to-end process related to how we integrate Jenkins on our .NET core project. Here we use GitLab as version control. So whenever a developer pushes their code on the master branch at that time Jenkins pipeline will automatically trigger and follow the processes like build, test, publish and deploy.
In this blog, we are not going deep into Jenkins as it is out of the scope for the current blog, but you can find all the details for Jenkins here…
- Gitlab Account (If you haven’t a GitLab account then click here… to open the account)
- You have to install Jenkins in your machine. (Download Jenkins from here…)
Please follow the following step to configure the Jenkins pipeline.
Open Jenkins and click on New Item
After clicking on “New Item”, you will be redirected to the “newJob” page then select Freestyle project and enter your project name.
After setting the project name, click “OK” to continue.
After clicking “OK”, you will redirect to the “configure” page.
On this configure page you have to set “Source Code Management”. Select “git” and enter your repository link, set credential, and select the specific branch.
After completing all the things just apply the created settings and click on save.
After completing the “configure” you have to build your project by clicking Build Now button.
After building your project you can see all the source code is available under the Workspace folder.
As we know we have to set CI/CD for our .NET project. So, that’s why we have to set install .NET SDK and .NET runtime on the server using the below commands. Then only we can use dotnet commands.
In the Build section select “Execute shell”.
The command is below list out
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb sudo apt-get update sudo apt-get install -y apt-transport-https sudo apt-get update sudo apt-get install -y dotnet-sdk-3.1
After writing the command again click on “Add build step” and select “Execute Shell”.
Path is: Configure > Build > Execute Shell
Now we have to write a command for the building project, run test cases and then after if everything successfully then deployed the project. So, to perform those actions we have to add particular command.
The command is below list out
dotnet restore code/code.api/code.api.csproj dotnet build code/code.api/code.api.csproj --configuration RELEASE dotnet test code/code.testing/code.testing.csproj --configuration RELEASE dotnet publish code/code.api/code.api.csproj --configuration RELEASE --output API
After writing all the commands, we have to build our project. Then
after a successful build, under the workspace folder, we are able to see our build.
As we know after the successfully generated build we have to upload our build to our server.
Here we use the FTP service to upload the build to our server.
Integrate FTP server and Deploy publish file automatically on the server.
So, first of all, we have to add FTP plugins to Jenkins.
So, first, select “Manage Jenkins” then after inside that select the “Manage Plugins” tab and write down the plunging name “Publish over FTP”
The path is: Manage Jenkins > Manage Plugins > “Install Publish over FTP” Package.
After installing the FTP package, we have to configure our FTP service.
So, first, select “Manage Jenkins” then after inside that select the “Configure System” tab and after that select “Publish over FTP” and write down FTP details.
The path is: Manage Jenkins > Configure System > Publish over FTP (Add FTP server)
After filling-up FTP details save the FTP configuration.
Now, we have to set FTP details in our project.
So, for that select project then after select configure and then after select post-build Actions where we have to add FTP details.
The Path is : Dashboard > Project > Configure > Post-build Actions
Select “Send Build artifacts over FTP”
Right now, we were doning setting by Jenkins’s side.
Now, we have to integrate GitLab Webhook into our GitLab account. In this blog, we are not able to cover more details about “Webhooks”. To get more details about “Webhooks” click here…
So, integrate Webhook in GitLab please follow the below path.
The path is: Open Gitlab > Project > Setting > Integrations > Jenkins CI
After integrating Webhook successfully, whenever we push code in our repository using webhook our pipeline will trigger automatically on Jenkins.
In this article, we have learned how to implement CI\CD with Jenkins using the GitLab account. I hope the steps and snippets in the blog will help you to understand & implement CI\CD with your project.
Thank you 🙂 for taking the time to read this article.
I hope this will help you 🤗.
Share via social media