0

I need to run every pipeline in the same project in a different container, because each job is incremental and uses a tool (declared in settings.xml) inside of my docker image, the simultanious use of this tool is forbidden and causes the jobs to fail if they run simultaiously, this case is so common coz there are multiple branches and MR on WIP, I searched the whole internet for a configuration of the runner or gitlab-ci.yml with no avail.

my .gitlab-ci.yml :

# ===================================================
# # Stage
# # ==================================================
stages:
  - Build


# ===================================================
# # Global variables
# # ==================================================
variables:
    GIT_CLONE_PATH: '$CI_BUILDS_DIR/$CI_JOB_ID/$CI_PROJECT_NAME'

# ===================================================
# # Job Templates
# # ==================================================
.job_template: &job_definition_java
  image: my.project/build-env:latest
  tags:
    - docker
    - compliancy
    - docker-executor
  before_script:
    - Xvfb :1 -noreset &

# ===================================================
# # Anchors
# # ==================================================
.extract_changes: &extract_changes
  - git remote set-url origin http://username:[email protected]/path/to/project.git
  - git fetch origin > log
  - LastTargetCommit=$(git rev-parse remotes/origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME)
  - LastCurrentCommit=$(git rev-parse HEAD)
  - git show --pretty="format:" --name-only $LastTargetCommit..$LastCurrentCommit | sort | uniq > CommitFile
  - sed -i '/^$/d' CommitFile
  - sed -i '/^Config/ d' CommitFile
  
.filter_changes: &filter_changes
  - |
    while read line; do
      GrandParentDir=$(echo "$line" | cut -d "/" -f1);
      ParentDir=$(echo "$line" | cut -d "/" -f2);
      ModuleDir=$(echo "$line" | cut -d "/" -f3);
      ModulePath="$GrandParentDir"/"$ParentDir"/"$ModuleDir";
      if [ -d "$ModulePath" ]; then
        if grep "$ModuleDir" $WD/$GrandParentDir/$ParentDir/pom.xml > /dev/null; then
          if [ $ParentDir == "BS" ]; then
            echo $ModulePath >> BSFILE;
          elif [ $ParentDir == "Modules" ]; then
            echo $ModulePath >> ModuleFILE;
          fi
        fi
      fi
    done < CommitFile

.sort_bs: &sort_bs
  - |
    if [ -f BSFILE ]; then
      while read bs; do
        X=$(echo "$bs" | cut -d "/" -f1);
        A=$(echo "$bs" | cut -d "/" -f2);
        B=$(echo "$bs" | cut -d "/" -f3);
        grep -n ">$B<" $X/$A/pom.xml >> BSs;
      done < BSFILE
      sort -n BSs > BSLIST ; sed -i 's/[0-9]//g ; s/\(.\{1\}\)// ; s/<module>//g ; s/ //g ; s/<.*//g' BSLIST ; sed -i -e 's/^[[:space:]]*//' BSLIST; sed -i -e 's#^#Components/BS/#' BSLIST;
      cat BSLIST >> FILE;
    fi
      
.sort_modules: &sort_modules
    - |
      if [ -f ModuleFILE ]; then
        while read module; do
          X=$(echo "$module" | cut -d "/" -f1);
          A=$(echo "$module" | cut -d "/" -f2);
          M=$(echo "$module" | cut -d "/" -f3);
          grep -n ">$M<" $X/$A/pom.xml >> Modules;
        done < ModuleFILE
        sort -n Modules > MODLIST ; sed -i 's/[0-9]//g ; s/\(.\{1\}\)// ; s/<module>//g ; s/ //g ; s/<.*//g' MODLIST ; sed -i -e 's/^[[:space:]]*//' MODLIST; sed -i -e 's#^#Components/Modules#' MODLIST;
        echo "modlist: $MODLIST";
        cat MODLIST >> FILE;
      fi

.filter_changes_ignore_sort: &filter_changes_ignore_sort
    - |
      while read line
      do
        GrandParentDir=$(echo "$line" | cut -d "/" -f1)
        ParentDir=$(echo "$line" | cut -d "/" -f2)
        ModuleDir=$(echo "$line" | cut -d "/" -f3)
        ModulePath="$GrandParentDir"/"$ParentDir"/"$ModuleDir"
        if [ -d "$ModulePath" ]; then
          if grep "$ModuleDir" $WD/$GrandParentDir/$ParentDir/pom.xml > /dev/null
          then
            echo $ModulePath >> FILE
          fi
        fi
      done < CommitFile
      
# ===================================================
# # Build Stage
# # ==================================================
build_changes:
  stage: Build
  only:
    - merge_requests
  <<: *job_definition_java
  script:
    - WD=$(pwd)
    - *extract_changes
    - *filter_changes
    - *sort_bs
    - *sort_modules
    - |
      if [ -f FILE ]; then
        sed -i '/^$/d' FILE;
        cat  FILE | uniq > BuildList
        while read line;  do
          echo -e "${TXT_BLUE}Building : ${TXT_CLEAR}$line";
          cd $WD/$line;
          mvn clean install -U -B -P jenkinsBuildProfile,BuildSimulation -Dmaven.repo.local=$WD/.m2/repository -Dsonar.session.id=$CI_PIPELINE_ID;
          if [ $? = 1 ]; then
            echo -e "${TXT_RED}PATH Error : $line";
            exit 1;
          fi
        done < BuildList
        if [ $? = 1 ]; then
          exit 1;
        fi
      fi

My config.toml :

concurrent = 3
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "docker-shared-runner"
  url = "http://my.gitlab.com/"
  token = "XXXX"
  executor = "docker"
  output_limit = 20000
  [runners.custom_build_dir]
    enabled = true
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0

1 Answer 1

0

Turns out that my runner is locked, unlocking it resolved my problem and i have different containers for the same project.

Unlocked via the gitlab Ui : Admin area > Runners > select the runner and uncheck the highlighted box Image here

Regards

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.