【发布时间】:2020-02-16 03:03:39
【问题描述】:
您好,我正在尝试使用 jenkins 构建 dotnetcore 项目。下面是我的文件结构。
locationservices.api
locationservices.api
locationservices.api.sln
Dockerfile
Jenkinsfile
locationservices.api.csproj
startup.cs
//rest of the files
下面是我的詹金斯文件。
stage('Build') {
agent {
docker {
image 'microsoft/dotnet:2.1-sdk'
args '-u root:root'
}
}
steps {
sh 'apt update'
sh 'apt install -y make'
sh 'apt install -y apt-transport-https'
sh 'echo "{\\\"buildNumber\\\":\\\"${BUILD_NUMBER}\\\", \\\"sha\\\":\\\"need to populate\\\"}" > locationservices.api/buildinfo.json'
sh 'dotnet publish -c Release -o out'
sh 'chmod a+rw -R .'
stash name: 'mws-out', includes: 'locationservices.api/out/**'
}
}
stage('Upload to ECR') {
when {
branch 'master'
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
agent {
label 'ec2-amazonlinux-v1'
}
steps {
unstash name: 'mws-out'
script {
docker.build("location/location-service:v_${env.BUILD_NUMBER}", "--build-arg http_proxy=${env.http_proxy} --build-arg https_proxy=${env.https_proxy} .")
docker.withRegistry('path', "ecr") {
docker.image("location/location-service:v_${env.BUILD_NUMBER}").push("v_${env.BUILD_NUMBER}")
docker.image("location/location-service:v_${env.BUILD_NUMBER}").push("latest")
}
}
}
下面是我的dockerfile
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["locationservices.api.csproj", "locationservices.api/"]
RUN dotnet restore "locationservices.api.csproj"
COPY . .
WORKDIR "/src/locationservices.api"
RUN dotnet build "locationservices.api.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "locationservices.api.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "locationservices.api.dll"]
当我在管道中运行时,出现以下错误。
Step 6/17 : WORKDIR /src
---> Using cache
---> 4cc3caf28136
Step 7/17 : COPY locationservices.api/locationservices.api.csproj locationservices.api/
---> Using cache
---> 2ecf1c39cc4a
Step 8/17 : RUN dotnet restore "locationservices.api.csproj"
---> Running in ba3d3b8d630a
[91mDid you mean to run dotnet SDK commands? Please install dotnet SDK from:
https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
[0mThe command '/bin/sh -c dotnet restore "locationservices.api.csproj"' returned a non-zero code: 145
我不确定为什么我不能在 jenkins 中构建我的项目。恢复时失败。有人可以帮我解决这个问题吗?任何帮助将不胜感激。谢谢
【问题讨论】:
-
jankins所在的服务器上是否安装了.netcore SDK?
-
嗨,如果没有sdk,还有其他方法可以创建图像吗?
-
如果没有 SDK,您将无法使用恢复、构建、发布等命令。我不确定您是否需要它们来创建 Docker 映像,因为我不熟悉 Docker。
标签: docker jenkins .net-core docker-build