skip to Main Content

I have Installed Gitlab in one of the Ubuntu machine. And I have dotnetcore project in the name of ABC in the Gitlab.

But, In that ABC repo have multiple small doetnetcore application with different different directory like abc1 abc2 abc3 abc4.

I want to write a single pipeline under ABC to create the docker Image whenever developer push the code in the respective directory. but that need to be create docker Image for that only directory.

eg: Developer push the code under abc3 directory, that time pipeline run and create the docker Image for only abc3 directory.

Please help me out with it.
Thanks in Advance…!!!

Below is my pipeline what I have written also Docker file:

stages:
  - docker
  - build
  
services:
  - docker:dind
  
before_script:
    - "echo $gitlab"

docker-job:
  stage: docker
  image: docker:dind
  script:
    - docker login -u username -p password $CI_REGISTRY
    - docker build -t dotnetcore .
    #- docker push $IMAGE_PUSH:latest
build:
  stage: build
  tags: 
    - shell
  image: mcr.microsoft.com/dotnet/sdk
  script:
    - dotnet restore
    - dotnet build


FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80

ENV ASPNETCORE_URLS=http://+:80

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["dotnetcore.csproj","./"]
RUN dotnet restore "dotnetcore.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "dotnetcore.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "dotnetcore.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "dotnetcore.dll"]

In this pipeline and dockerfile I am only able to build "dotnetcore" project. But I have dotnetcore1 doctnetcore2 dotnetcore3 projects under the same Repo.

2

Answers


  1. Assuming you have a small number of directories. You can create a job for each directory. Use rules with changes to check if changes were made in the particular directory.

    Login or Signup to reply.
  2. gitlab ci has a only:changes feature. You can define multiple jobs, each for one docker.

    job-a:
      script: docker build a
      only:
        changes:
          - a/**/*
    job-b:
      script: docker build b
      only:
        changes:
          - b/**/*
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search