我有一个Kubernetes集群(AWS EKS Master-EC2节点)和其中的Jenkins pod。我使用Jenkins的Kubernetes插件来创建Jenkins从属Pod。在构建Dockerfile时,关于dotnet restore命令,我的从属Pod失败。我可以在本地构建Dockerfile。问题出在哪里?你能指导我吗?我想nuget存在某种代理问题,但我不知道如何告诉nuget使用Kubernetes代理。
使用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输出:
/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