Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run pipeline only on HEAD commit in GitlabCi runner?

we have a CI pipeline on our repository, hosted in gitlab

we setup gitlab-runner on our local machine

the pipeline running 4 steps

  • build

  • unit tests

  • integration test
  • quality tests

all this pipeline takes almost 20 min

and the pipeline trigger on each push to a branch

is there a way to configure the gitlab-runner that if the HEAD of a branch that the runner currently running on changes the pipe will auto cancel the run? because the latest version is what matters

for example in this run the lower run is unnecessary

enter image description here

gitlab-ci.yml

stages:
  - build
  - unit_tests
  - unit_and_integration_tests
  - quality_tests

build:
  stage: build
  before_script:
    - cd projects/ideology-synapse
  script:
    - mvn compile


unit_and_integration_tests:
  variables:
    GIT_STRATEGY: clone
  stage: unit_and_integration_tests
  only:
    - /^milestone-.*$/
  script:
    - export RUN_ENVIORMENT=GITLAB_CI
    - export MAVEN_OPTS="-Xmx32g"
    - mvn test
    - "cat */target/site/jacoco/index.html"
  cache: {}
  artifacts:
    reports:
      junit:
        - "*/*/*/target/surefire-reports/TEST-*.xml"


unit_tests:
  variables:
    GIT_STRATEGY: clone

  stage: unit_tests
  except:
    - /^milestone-.*$/
  script:
    - export MAVEN_OPTS="-Xmx32g"
    - mvn test
    - "cat */target/site/jacoco/index.html"
  cache: {}
  artifacts:
    reports:
      junit:
        - "*/*/*/target/surefire-reports/TEST-*.xml"

quality_tests:
  variables:
    GIT_STRATEGY: clone
  stage: quality_tests
  only:
    - /^milestone-.*$/
  script:
    - export RUN_ENVIORMENT_EVAL=GITLAB_CI
    - export MAVEN_OPTS="-Xmx32g"
    - mvn test
  cache: {}

edit after @siloko comment:

I already try using the auto-cancel redundant, pending pipelines in the setting menu

I want to cancel running pipelines and not pending

like image 701
Naor Tedgi Avatar asked Apr 03 '19 13:04

Naor Tedgi


1 Answers

after forther investigation, I found that I had 2 active runners on one of my machines one shared runner , and another specific runner then if I push a 2 commit one after another to the same branch both of the runners take the jobs and execute them. that also explains why

Auto-cancel redundant, pending pipelines 

options, didn't work because it works only when the same runner have pending jobs

actions that been taken to fix this problem: unregister the specific runner and leave the machine only with the shared runner

like image 99
Naor Tedgi Avatar answered Nov 01 '22 12:11

Naor Tedgi