DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Java CI/CD: From Local Build to Jenkins Continuous Integration
  • Recipe To Implement the Jenkins Pipeline For MuleSoft Application [Videos]
  • Jenkins in the Age of Kubernetes: Strengths, Weaknesses, and Its Future in CI/CD
  • Implementing CI/CD Pipelines With Jenkins and Docker

Trending

  • Distributed Consensus: Paxos vs. Raft and Modern Implementations
  • Simpler Data Transfer Objects With Java Records
  • Implementing Explainable AI in CRM Using Stream Processing
  • How to Introduce a New API Quickly Using Micronaut
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Continuous Integration (CI) for .NET Core Projects: .NET Core CLI Part III

Continuous Integration (CI) for .NET Core Projects: .NET Core CLI Part III

Learn how to set up a Jenkins pipeline for continuous integration of your nNet Core projects in this tutorial.

By 
Neel Bhatt user avatar
Neel Bhatt
·
Jul. 18, 18 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
43.4K Views

Join the DZone community and get the full member experience.

Join For Free

This is the 3rd post on .NET Core CLI commands. You can find the first 2 posts below:

  1. Guide to create and run .NET Core application using CLI Tools: .NET Core CLI Part I

  2. Guide to Create and Publish Nuget packages using .Net Core CLI: .NET Core CLI Part II

In this post, we will create a basic Continuous Integration(CI) using .NET Core CLI commands and Jenkins pipeline.

Jenkins Pipeline

What is Jenkins Pipeline?

Jenkins Pipeline is a suite of plugins that supports implementing and integrating continuous delivery pipelines into Jenkins. Pipeline provides an extensible set of tools for modeling simple-to-complex delivery pipelines "as code" via the Pipeline DSL.

Basically, it is a Groovy script-based language which is used to describe stages and steps within a pipeline.

We will not go deep into Jenkins Pipeline as it is out of the scope of the current post, but you can find all the details for the Pipeline here.

I hope you are a little bit aware of Jenkins Pipeline now and I hope you have your basic setup done for Jenkins. You can download Jenkins here.

Create a Jenkins Pipeline

We will require a Jenkins pipeline for our CI where we will put all code required to run our CI. Let us create our pipeline from scratch.

Open Jenkins and click on New Item:In the next window, select the pipeline option and give your pipeline a name:

Our pipeline is ready — we will come back to the pipeline once we will finalize our Pipeline code.

Let us add different stages which will be required to run our CI.

For this post, we will use the SampleCliApp which we created in the last post. I have pushed the code here.

Checkout

The first step for our CI would be to checkout the code from Git. For that, our pipeline code would be as below:

stage('Checkout') {
 steps {
  git credentialsId: 'userId', url: 'https://github.com/NeelBhatt/SampleCliApp', branch: 'master'
 }
}

Here:

  • git credentialsId: generally the ID by which you will access the git repo
  • url: GIT URL of your project
  • branch: Branch on which you want to set the CI

Once done, the project would be checked out\cloned on the agent which you have specified

Restore

Next step would be the restoring of the packages of the application.

Let us run the restore command, which will restore the packages if they are not available on your Windows agent:

stage('Restore Packages') {
 steps {
  bat "dotnet restore"
 }
}

This will restore the missing packages.

Clean

Next step is to clean the solution.

For that, let us add the clean command in the pipeline:

stage('Clean') {
 steps {
  bat "dotnet clean"
 }
}

This will clean the solution.

Build

Next step is building the solution. We will build our solution on the agent using dotnet cli commands.

For that, let us add the build command in the pipeline:

stage('Build') {
 steps {
  bat "dotnet build --configuration Release"
 }
}

This will build the solution. It will put dlls and other built files under bin\Debug\netcoreapp2.x

Pack

Once the solution is built, the next step is to create the Nuget package which we will publish to our desired location. The nuget package is nothing but the glorified zip and it contains the same things as the published build.

For that, let us add the pack command in the pipeline:

stage('Build') {
 steps {
  bat "dotnet pack --no-build --output nupkgs"
 }
}

Above command will skip the build step and will put the nuget packages under nupkgs folder.

After this step, the Nuget packages will be created and would be stored under nupkgs folder

Publish

The next step is to publish our Nuget packages to storage.

As we have just created the Nuget package, we need some space to store our packages. Nuget.org provides a space where you can store your Nuget packages, but they are public so other developers can also see your packages. If you do not wish to use Nuget.org, then there are other options (more details here).

For this post, we will publish the package to Artifactory. Note that I have created an account in Artifactory, so if you choose to use Artifactory, please create an account there.

Let us add the publish command to publish our packages from Jenkins.

stage('Publish') {
 steps {
  bat "dotnet nuget push **\\nupkgs\\*.nupkg -k yourApiKey -s http://myserver/artifactory/api/nuget/nuget-internal-stable/com/sample"
 }
}

The above command will put my nuget packages in the Artifactory folder.

That is it. Now let us put all the pieces together to create the complete Jenkins pipeline

Complete Jenkins Pipeline

The complete Jenkins pipeline looks like below:

pipeline {
 agent any
 environment {
  dotnet = 'path\to\dotnet.exe'
 }
 stages {
  stage('Checkout') {
   steps {
    git credentialsId: 'userId', url: 'https://github.com/NeelBhatt/SampleCliApp', branch: 'master'
   }
  }
  stage('Restore PACKAGES') {
   steps {
    bat "dotnet restore --configfile NuGet.Config"
   }
  }
  stage('Clean') {
   steps {
    bat 'dotnet clean'
   }
  }
  stage('Build') {
   steps {
    bat 'dotnet build --configuration Release'
   }
  }
  stage('Pack') {
   steps {
    bat 'dotnet pack --no-build --output nupkgs'
   }
  }
  stage('Publish') {
   steps {
    bat "dotnet nuget push **\\nupkgs\\*.nupkg -k yourApiKey -s            http://myserver/artifactory/api/nuget/nuget-internal-stable/com/sample"
   }
  }
 }
}

Once we have the pipeline created, go back to the Jenkins Pipeline which we have created above and paste our pipeline code into the Configure as shown below:

Once the code is added, go back to the Jenkins UI and click on Build now.

This will run the Jenkins job which will do all the things required for CI:

Checkout -> Restore -> Clean -> Build -> Pack -> Publish

JenkinsFile

Currently, we have written the Jenkins pipeline code into the Jenkins pipeline configuration but a better approach would be to create a Jenkinsfile in the root of your application in Git as shown below:

Once you add the Jenkins file, just fill the details under Pipeline section as below:

Click on Build now, and CI should work.

We can add Test, Code Scan, etc steps for CI, but as the current post aims for a basic flow of CI, I have not added it.

I hope this helps.

Continuous Integration/Deployment Command-line interface .NET Pipeline (software) Jenkins (software) Integration

Published at DZone with permission of Neel Bhatt, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Java CI/CD: From Local Build to Jenkins Continuous Integration
  • Recipe To Implement the Jenkins Pipeline For MuleSoft Application [Videos]
  • Jenkins in the Age of Kubernetes: Strengths, Weaknesses, and Its Future in CI/CD
  • Implementing CI/CD Pipelines With Jenkins and Docker

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!