Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

CI/CD for .NET Core container applications on Red Hat OpenShift

<p>&nbsp;</p> <quillbot-extension-portal></quillbot-extension-portal>

October 17, 2019
Cheng Kuan Gan
Related topics:
.NETContainersKubernetes
Related products:
Red Hat OpenShift Container Platform

    Many people have done continuous integration and continuous delivery (CI/CD) for .NET Core, but they still may wonder how to implement this process in Red Hat OpenShift Container Platform (OCP). The information is out there, but it has not been structurally documented. In this article, we'll walk through the process.

    The CI/CD process for .NET applications

    The CI/CD process is fairly straightforward for .NET applications, with the following high-level process:

    1. Start Jenkins to check out the Jenkinsfile.
    2. Get the .NET Core source code from Gogs.
    3. Continue according to the configured pipelines, which in this case means:
      1. Run dotnet restore to restore the NuGet packages from the Nexus repository.
      2. Run dotnet publish to build and publish the .dll files.
      3. Run oc start-build to build the container image using the published .dll files, which deploys or redeploys the container when the image build in the Development project is completed.
      4. Tag the image in the Development project (in this example, the tag is sampledotnet:UATReady-1.0.0), which triggers an image pulled from the Development project to the user acceptance testing (UAT) project.

    The required Openshift artifacts for the Development and UAT projects are preconfigured in the next section by using the sample template, which you can download from GitHub.

    Configuring OpenShift

    Note: You may wish to change some of the paths and parameters according to your environment.

    To configure Red Hat OpenShift for our example CI/CD process, complete the following steps.

    1. Create your OpenShift projects:
    oc new-project demo-dev --display-name="Development"
    oc new-project demo-uat --display-name="UAT"
    oc new-project demo-tools --display-name="CI/CD Tools"
    1. Apply the necessary permissions so Jenkins can modify and access the Development and UAT projects. We also need to grant permission for the UAT project to pull images from the Development project:
    oc policy add-role-to-user edit system:serviceaccount:demo-tools:jenkins -n demo-dev
    oc policy add-role-to-user edit system:serviceaccount:demo-tools:jenkins -n demo-uat
    oc policy add-role-to-user system:image-puller system:serviceaccount:demo-uat:default -n demo-dev

    Note: If these lines result in "Warning: ServiceAccount 'jenkins' not found," this message can be ignored.

    1. Deploy the necessary CI/CD tools:
    oc new-app -f https://raw.githubusercontent.com/chengkuangan/templates/master/gogs-persistent-template.yaml -p SKIP_TLS_VERIFY=true -p DB_VOLUME_CAPACITY=1Gi -p GOGS_VERSION=latest -p GOGS_LIMIT_CPU=300m -p GOGS_LIMIT_MEM=256Mi -p POSTGRESQL_LIMIT_CPU=200m -p POSTGRESQL_LIMIT_MEM=256Mi -n demo-tools
    oc new-app -f https://raw.githubusercontent.com/chengkuangan/templates/master/nexus3-persistent-templates.yaml -p NEXUS_VOLUME_CAPACITY=20Gi -p NEXUS_VERSION=latest -p NEXUS_LIMIT_CPU=1 -p NEXUS_LIMIT_MEM=3Gi -n demo-tools
    oc new-app jenkins-persistent -n demo-tools
    oc create -f https://raw.githubusercontent.com/chengkuangan/dotnetsample/master/templates/dotnet-jenkins-slave.yaml -n demo-tools

    Note: Typically Microsoft Team Foundation Server (TFS) is used for source control management (SCM) in the Microsoft world; however, Gogs is used in this example mainly because there is no TFS available for me to try out. If TFS is the use case, you will need to install the TFS plugin for Jenkins to enable integration between Jenkins and TFS.

    Now, you can see your deployed tools in OpenShift:

    CI/CD tools in OpenShift.

    You may receive an error where the .Net Jenkins slave could not be started due to a missing ImageStream, like so:

    ImageStream dotnet-22-jenkins-slave-rhel7 is Not Found

    In this case, the image above shows an error in the Jenkins pod indicating that the ImageStream dotnet-22-jenkins-slave-rhel7 is not found. To fix this problem, you would change the following in the dotnet-jenkin-slave.yaml file to use the correct URL path for the ImageStream setting:

    <image>dotnet-22-jenkins-slave-rhel7:latest</image>

    Or, you can modify the ConfigMap created earlier (named dotnet-jenkins-slave-22 in this example).

    1. Deploy the .NET Core artifacts using the .NET Core templates. Notice the parameter --allow-missing-imagestream-tags=true, which indicates that we do not have any images available until we build them in when we run the pipelines:
    oc new-app -n demo-dev --allow-missing-imagestream-tags=true -f https://raw.githubusercontent.com/chengkuangan/dotnetsample/master/templates/dotnet-template.yaml -p IMAGE_PROJECT_NAME=demo-dev -p IMAGE_TAG=latest -p APPLICATION_NAME=sampledotnet
    oc new-app -n demo-uat --allow-missing-imagestream-tags=true -f https://raw.githubusercontent.com/chengkuangan/dotnetsample/master/templates/dotnet-nobuild-template.yaml -p IMAGE_PROJECT_NAME=demo-uat -p IMAGE_TAG=UATReady-1.0.0 -p APPLICATION_NAME=sampledotnet
    1. Log into Gogs and clone the .NET Core sample code from https://github.com/chengkuangan/dotnetsample.git, shown below:

    The cloned .Net Core source code in Gogs

    1. Create a Jenkins Pipeline item as shown here:

    Create a Jenkins Pipeline.

    1. Point the Git URL to the Gogs repository URL:

    Choose Pipeline Script from SCM lets you enter the Gogs service URL in the Repositories field.

    1. Go the Jenkins item just created and click Build Now. The .NET apps will be built and deployed in no time.

    Changing the .NET project files

    The following summarizes the changes required in the .NET project files:

    1. Introduce RuntimeIdentifier into the existing .csproj file to indicate that this project should be built for the Red Hat Enterprise Linux 7 environment:
      <PropertyGroup>
        <TargetFramework>netcoreapp2.2</TargetFramework>
        <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
        <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
        <UserSecretsId>0a9f43ee-3c69-42b2-9766-c1b35bafeebd</UserSecretsId>
        <RuntimeIdentifier>rhel.7-x64</RuntimeIdentifier>
      </PropertyGroup>
    1. Add NuGet package configuration into the .csproj and .deps.json files to test whether the Nexus works as expected for NuGet packages. A snippet of this configuration change is shown below:
      <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0"/>
        <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
        <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.4.10" />
        <PackageReference Include="Dapper" Version="1.60.6"/>
      </ItemGroup>
    1. For the .NET apps build process to refer to our predefined repository in Nexus, we need to create a nuget.config file in the project's root folder. Use the following configuration as the bare minimum settings. Notice the Nexus_Packages under <packageSources>, where we set the proxy repository in the Nexus server:
      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
          <packageRestore>
              <!-- Allow NuGet to download missing packages -->
              <add key="enabled" value="True" />
              <!-- Automatically check for missing packages during build in Visual Studio -->
              <add key="automatic" value="True" />
          </packageRestore>
          <solution>
              <add key="disableSourceControlIntegration" value="true" />
          </solution>
          <packageSources>
              <add key="Nexus_Packages" value="http://nexus3-demo-tools.apps.ocp.demo.com/repository/nuget.org-proxy/" />
          </packageSources>
      </configuration>
    1. Create the following Jenkinsfile in the project's root folder:
    #!groovy
    def DEV_PROJECTNAME = "demo-dev"
    def UAT_PROJECTNAME = "demo-uat"
    def BUILDCONFIGNAME="sampledotnet"
    def IMAGE_NAME="sampledotnet:latest"
    def UATIMAGENAME = "sampledotnet:UATReady-1.0.0"
    node('dotnet-22') {
      stage('Clone') {
        checkout scm
      }
      stage('Restore') {
        sh "dotnet restore Test.csproj --configfile nuget.config --force --verbosity d"
      }
      stage('Publish') {
        sh "dotnet publish Test.csproj --no-restore  -c Release /p:MicrosoftNETPlatformLibrary=Microsoft.NETCore.App"
      }
      stage('Build Image') {
        sh "oc -n $DEV_PROJECTNAME start-build $BUILDCONFIGNAME --from-dir=./bin/Release/netcoreapp2.2/rhel.7-x64/publish --follow"
        sh "oc -n $DEV_PROJECTNAME tag $DEV_PROJECTNAME/$IMAGE_NAME $UAT_PROJECTNAME/$UATIMAGENAME"
      }
    }

    Note: You may create the pipelines as part of YAML config in Openshift. However, I personally prefer to keep the Jenkinsfile as part of the project files in the source control system.

    As illustrated in the above pipelines, instead of using the dotnet publish command to perform both the restore and publish processes, a --no-restore parameter is specified. This setup is to keep the command from calling the dotnet restore command automatically, which would cause it to bypass the nuget.config and directly connect to nuget.org to download the nuget packages. We introduce another stage before the Publish stage to explicitly call the dotnet restore command by pointing to nuget.config.

    I hope this article helps you implement CI/CD for .NET Core using Red Hat OpenShift Container Platform.

    References

    • Red Hat OpenShift Container Guidelines
    • .NET Core 2.2 Container Getting Started Guide
    • Sample dotnet project used in this tutorial
    • dotnet publish command guide
    • dotnet restore command guide
    • nuget.config reference
    • NuGet documentation
    Last updated: January 12, 2024

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.