How to run gitlab ci template in separate jobs for each iterationn

I’m using below script for code build stage. i need to run each iterations in separate jobs. iteration depends on before_script.sh. I’m getting project names from that file before_script.sh.

example:
Project 1 ---->>> Job 1
Project 2 ----->>> Job 2

# Nightly build
.nightly_build_and_release:
  stage: build
  image: docker:24.0.5-cli-alpine3.18
  variables:
    M2_REPO: "$CI_PROJECT_DIR/.m2/repository"
    M2_SETTINGS: "$CI_PROJECT_DIR/.m2/settings.xml"
    DOCKER_DRIVER: overlay2
    POM_XML_FILE: java/containers/pom.xml
    PROJECT_NAME:
    M2_EXTRA_OPTS:
  cache:
    key: backend-cache
    paths:
      - java/*/target
      - $CI_PROJECT_DIR/.m2/repository
    policy: pull-push
  before_script:
    - source before_script.sh
  script:
    - |
      # Source before_script.sh to generate the list of projects and servers
      source before_script.sh || { echo "Error: before_script.sh failed"; exit 1; }
      
      # Iterate over the list of projects and servers
      while true; do
          read -r project server || break
          echo "Processing project: $project, server: $server"
          export PROJECT_NAME="$project"
          export SERVER_IP="$server"
          echo "Building and releasing $PROJECT_NAME to server at $SERVER_IP"
          echo "Building and releasing job started. Building for project $PROJECT_NAME."
          apk update
          apk add maven openjdk11
          docker login -u admin -p _test_ 192.168.25.456:8084
          cd /builds/java
          # build master pom
          mvn clean install -s "$M2_SETTINGS" -Dmaven.repo.local="$M2_REPO" -N
          # build all java binaries
          mvn clean install -s "$M2_SETTINGS" -Dmaven.repo.local="$M2_REPO" -Test=$PROJECT_NAME -Dmaven.javadoc.skip=true -DskipTests -Dorg.slf4j.simpleLogger.defaultLogLevel=WARN -T 1C -B
          # container builds
          cd containers
          mvn clean install -s "$M2_SETTINGS" -Dmaven.repo.local="$M2_REPO" -N
          # if target is null it will be set to the current value of $PROJECT_NAME
          : "${TARGET:=$PROJECT_NAME}"
          mvn clean deploy -s "$M2_SETTINGS" -Dmaven.repo.local="$M2_REPO" -Dproject=$TARGET -Drepo.username=$MVN_USERNAME -Drepo.password=$MVN_PASSWORD $M2_EXTRA_OPTS
          #- docker image prune -f
      done < <(source before_script.sh || exit 0)

build_and_release_servers:
  extends: .nightly_build_and_release
  tags:
    - fast
  only:
    refs:
      - develop