DEV Community

Jethro Daniel
Jethro Daniel

Posted on


Setup a CI/CD Pipeline For .Net Core With CircleCI

CircleCI in recent years have shown their commitment in recent years in ensuring that they make the task of continous integration and delivery way more easier and fast for devs to setup. And amongst the many CI/CD tools in the market today, i think CircleCI have one of the easiest and straight forward approach. Making use of containers.

However with the list of programming languages they wrote convenience images for they somehow neglected .Net...anyways the joke is on them. I recently explored using them on a project, and came up with the following.

I dug into their convenience images and found out that they just basically have docker bundled with the language's base image.

So i was easily able to come up with one for .Net Core. i used .Net Core 3, but same approach should work on previous versions

GitHub logo Herocod3r / CircleCiDocker.Net

CircleCi Convenience images for .Net Core


CircleCi Convenience images for .Net Core

After building the image i pushed it to Docker Hub

Next step was to add my circle ci config file

Create a folder in the root directory of your file named .circleci within it create a file called config.yml

then define the following

version: 2
      - image: jetcipher/circleci-dotnet-core:3.0
      - checkout
      - run:
          name: Restore
          command: dotnet restore
          working_directory: MyProject.Api
      - run:
          name: Build
          command: dotnet build -c Release
          working_directory: MyProject.Api
      - run:
          name: Running Tests
          command: dotnet test
          working_directory: MyProject.Tests
      - setup_remote_docker:
          docker_layer_caching: true
      - run:
          name: Build and push Docker image
          command: |
            docker build -t MyProject .
            echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN --password-stdin
            docker tag boku herocod3r/MyProject
            docker push herocod3r/MyProject

MyProject is your project's name, im sure you get the flow πŸ™‚
On your CircleCI project's dashboard setup the enviroment variables DOCKER_PWD your docker password and DOCKER_LOGIN your docker id

Commit and push, voila your build should now be running !!

Top comments (2)

alex75it profile image

Hi Jethro,
just a note.
I have a personal free plan of Circle CI and this is the error I receive:
This job has been blocked because Docker Layer Caching is not available on your plan. Please upgrade to continue building.

herocod3r profile image
Jethro Daniel

oh, you might have to turn off Docker Layer Caching for the free plan

     - checkout 
     - setup_remote_docker: 
         docker_layer_caching: false