Kubernetes Jenkins Slave Pod - Dotnet Restore problem

5/20/2019

I have a Kubernetes cluster(AWS EKS Master-EC2 Node) and Jenkins pod inside of it. I used Jenkins's Kubernetes plugin to create Jenkins Slave pods. My slave pod is failing when it comes to dotnet restore command while building the Dockerfile. I can built the Dockerfile locally. Where is the problem? Can you guide me about it? I guess there is some kind of proxy problem with nuget but i don't know how i can tell to nuget to use Kubernetes proxies.

Application developed with Asp.Net Core

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build

WORKDIR /app

COPY ./SampleWebApiAspNetCore/*.csproj ./
RUN dotnet restore --verbosity d


COPY . ./
RUN dotnet publish -c Release -o output


FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
COPY --from=build /app/SampleWebApiAspNetCore/output .

EXPOSE 5000
ENV ASPNETCORE_URLS http://*:5000
ENV ASPNETCORE_ENVIRONMENT docker

ENTRYPOINT ["dotnet", "SampleWebApiAspNetCore.dll"]

Jenkinsfile:

pipeline {
  agent {
    kubernetes {
      label 'mypod'
      yaml """
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: docker
    image: docker:latest
    command: ['cat']
    tty: true
    volumeMounts:
    - name: dockersock
      mountPath: /var/run/docker.sock
  volumes:
  - name: dockersock
    hostPath:
      path: /var/run/docker.sock
"""
    }
  }
  stages {
    stage('Build Docker image') {
      steps {
        git url: 'https://github.com/TEST/KubernetesJenkins.git'
        dir('NetCoreWebApplication'){
        container('docker') {
          script {
              sh "whoami"
              sh "ls -l"
              sh "apk update"
              sh "apk upgrade"
               def image = docker.build('dorukakinci/netcore-demo-restwebapplication')
                image.inside() {
                  sh "whoami"
                }
              }
            }
          }
      }
    }
  }
}

Jenkinsfile Output:

/usr/share/dotnet/sdk/2.2.204/NuGet.targets(119,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/app/SampleWebApiAspNetCore.csproj]
/usr/share/dotnet/sdk/2.2.204/NuGet.targets(119,5): error :   Resource temporarily unavailable [/app/SampleWebApiAspNetCore.csproj]
The command '/bin/sh -c dotnet restore' returned a non-zero code: 1

Full verbose output https://gist.githubusercontent.com/DorukAkinci/8b4ffc2589aeabe34f35232b7a0b7560/raw/e37fdc99bcd27419fe142696720566d3bd4d2471/gistfile1.txt

-- Kerim Doruk Akıncı
.net-core
docker
jenkins
jenkins-pipeline
kubernetes

0 Answers