English 中文(简体)
Gitlab CI On Prem, Docker Image and ASP.NET Core 7
原标题:

We have a .NET 6 application. We added CI using:

image: mcr.microsoft.com/dotnet/sdk:6.0

before_script:
  -  dotnet restore --packages $NUGET_PACKAGES_DIRECTORY 
build:
  stage: build
  script:
    -  dotnet build --no-restore 

From https://gitlab.com/gitlab-org/project-templates/dotnetcore/-/blob/master/.gitlab-ci.yml

But we have an error:

dotnet command not found

I have tried with shared and custom linux runner but the same error keeps appearing.

问题回答

Take this. It will build you Docker image and push it into you Docker Hub image repository. Do not forget to create REGISTRY_USER and REGISTRY_PASS to login to DockerHub under project/settings/"CI/CD"/Variables.

stages:
  - test
  - build

image: mcr.microsoft.com/dotnet/sdk:7.0

variables:
  OBJECTS_DIRECTORY:  obj 
  NUGET_PACKAGES_DIRECTORY:  .nuget 
  SOURCE_CODE_PATH:  src/DemoApp/ 
  IMAGE_NAME: "your-account/demo-app"
  IMAGE_TAG: "1.0"
  
cache:
  # Per-stage and per-branch caching.
  key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
  paths:
    -  $SOURCE_CODE_PATH$OBJECTS_DIRECTORY/project.assets.json 
    -  $SOURCE_CODE_PATH$OBJECTS_DIRECTORY/*.csproj.nuget.* 
    -  $NUGET_PACKAGES_DIRECTORY 

  policy: pull-push
before_script:
  -  dotnet restore src/DemoApp/DemoApp.csproj --packages $NUGET_PACKAGES_DIRECTORY 

build_image:
  stage: build
  tags:
    - private
  image: docker:24.0.0-rc.4-cli
  services:
    - docker:24.0.0-rc.4-dind
  variables:
    DOCKER_TLS_CERTDIR: "/certs"
  before_script:
    - docker login -u $REGISTRY_USER -p $REGISTRY_PASS
  script:
    - docker build -t $IMAGE_NAME:$IMAGE_TAG .
    - docker push $IMAGE_NAME:$IMAGE_TAG

tests:
  stage: test
  tags:
    - private
  script:
    -  dotnet test src/DemoApp/DemoApp.csproj --no-restore 




相关问题
.NET 7 minimal API request timeout

I found this in .NET 8 (prerelease) but I can t use it due to company policy. https://learn.microsoft.com/en-us/aspnet/core/performance/timeouts?view=aspnetcore-8.0&viewFallbackFrom=aspnetcore-7.0 ...

Blazor web assembly pass checkbox list values to model

I m new to Blazor. I m working in a web assembly Blazor project. I am trying to create a form that passes values back to a model. I have it working with input text fields and drop downs, but I am ...

asp.net 6 c# mvc one to many get data from many side

I am trying to access the data on the many side of a one to many relationship. In the Index action of my controller I assign the data to a variable and return it. I have a Blog, the one side, with ...

How to update shared view adminheader.cshtml from a model

I ve added a drop down into my shared adminheader.cshtl view and it needs to be dynamically updated from data from a table. So when I use another view like routeplan.cshtml I load the view from ...

Gitlab CI On Prem, Docker Image and ASP.NET Core 7

We have a .NET 6 application. We added CI using: image: mcr.microsoft.com/dotnet/sdk:6.0 before_script: - dotnet restore --packages $NUGET_PACKAGES_DIRECTORY build: stage: build script: - ...

ASP.NET Core 2 .1 - How to show all data in table

I don t know how to put CustomerData into CustomerLists property. I m already using CustomerLists = CustomerData; but I got error: CustomerLists is a type but is used like a variable Can anyone ...

热门标签