adding .net core to docker container with Jenkins

You can run these commands inside the Docker container in order to install .NET Core. They can also be stored in a Dockerfile (as per @Zooly57)

Install the latest .NET Core 2.0:

sudo apt install libunwind8 gettext apt-transport-https
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 2.0

Or LTS version of .NET Core

sudo apt install libunwind8 gettext apt-transport-https
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel LTS

Contents of the script here: https://github.com/dotnet/cli/blob/master/scripts/obtain/dotnet-install.sh


As of this response you can use the following Dockerfile to get .NetCore 2 installed into the Jenkins container. You can obviously take this further and install the needed plugins and additional software as needed. I hope this helps you out!

FROM jenkins/jenkins:lts
 # Switch to root to install .NET Core SDK
USER root

# Just for my sanity... Show me this distro information!
RUN uname -a && cat /etc/*release

# Based on instructiions at https://docs.microsoft.com/en-us/dotnet/core/linux-prerequisites?tabs=netcore2x
# Install depency for dotnet core 2.
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    curl libunwind8 gettext apt-transport-https && \
    curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg && \
    mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg && \
    sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/dotnetdev.list' && \
    apt-get update

# Install the .Net Core framework, set the path, and show the version of core installed.
RUN apt-get install -y dotnet-sdk-2.0.0 && \
    export PATH=$PATH:$HOME/dotnet && \
    dotnet --version

# Good idea to switch back to the jenkins user.
USER jenkins

Fantastic answer by Dennis, it's exactly what I ended up doing. It was a nice introduction to Docker as well :-)

Here's my Dockerfile for Jenkins 2.249.2 (LTS at the time of writing) on Debian 9 (stretch):

# Extend Jenkins 2.249.2 on Debian 9 (stretch)
FROM jenkins/jenkins:2.249.2-lts

# Switch to root user to install .NET SDK
USER root

# Print kernel and distro info
RUN echo "Distro info:" && uname -a && cat /etc/*release

# Install needed tools and upgrade installed packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl apt-transport-https software-properties-common \
&& apt-get upgrade -y

# Add Microsoft repository for .NET SDK
RUN curl -sSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN apt-add-repository https://packages.microsoft.com/debian/9/prod/

# Install .NET SDK
RUN apt-get update \
&& apt-get install -y dotnet-sdk-3.1

# Switch back to jenkins user
USER jenkins

The dotnet command worked without setting any paths.

I guess when a newer version of Jenkins is released that uses Debian 10, I'll just update the FROM line then the Microsoft repository URL.