diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7483d5c..85f8c20 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,34 +1,75 @@
-before_script:
-  - mkdir build
-  - cd build
-  - source /cvmfs/pheno.egi.eu/HEJ/HEJ_env.sh && echo "sourced"
-  - cmake .. -DCMAKE_BUILD_TYPE=DEBUG
+.tags_template:
+  tags: &tags_def
+    - docker
 
-basic:
+stages:
+  - minimal
+  - extended_tests
+  - rivet
+  - QCDloop
+  - install
+  - clean
+
+.HEJ_compile:
+  tags: *tags_def
+  before_script:
+    - export HEJ_DIR=${PWD}
+    - source /cvmfs/pheno.egi.eu/HEJ/HEJ_env.sh && echo "sourced"
+    - cd ..
+    - mkdir -p tmp_HEJ/build_HEJ
+    - cd tmp_HEJ
+    - export HEJ_Install_DIR=${PWD}/HEJ_installed
+    - cd build_HEJ
+    - cmake ${HEJ_DIR} -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_INSTALL_PREFIX=${HEJ_Install_DIR}
+    - make -j 8
+    - make install
+
+Minimal_setup:
+  stage: minimal
+  extends: .HEJ_compile
   image: hejdock/hepenv
   script:
-  - make -j 8
-  - make test
-  - bash -c '[ -f tst.lhe ]' && echo "found LHE output"
-  tags:
-  - docker
+    - make test
+
+FOG:
+  stage: extended_tests
+  image: hejdock/hepenv
+  before_script:
+    - export FOG_DIR=${PWD}/FixedOrderGen
+    - source /cvmfs/pheno.egi.eu/HEJ/HEJ_env.sh && echo "sourced"
+    - cd ../tmp_HEJ
+    - export HEJ_Install_DIR=${PWD}/HEJ_installed
+    - export LD_LIBRARY_PATH=${HEJ_Install_DIR}/lib:${LD_LIBRARY_PATH}
+    - export LIBRARY_PATH=${HEJ_Install_DIR}/lib:${LIBRARY_PATH}
+    - mkdir -p build_FOG
+    - cd build_FOG
+    - cmake ${FOG_DIR} -DCMAKE_BUILD_TYPE=DEBUG
+    - make -j 8
+  script:
+    - make test
 
 rivet:
+  stage: rivet
+  extends: .HEJ_compile
   image: hejdock/rivetenv
   script:
-  - make -j 8
-  - make test
-  - bash -c '[ -f tst.hepmc ]' && echo "found HepMC2 output"
-  - bash -c '[ -f tst.yoda ]' && echo "found rivet output"
-  - rivet-cmphistos tst.yoda
-  - bash -c '[ -f MC_XS_XS.dat ]' && echo "yoda not empty"
-  tags:
-  - docker
+    - make test
+    - bash -c '[ -f tst.yoda ]' && echo "found rivet output"
+    - rivet-cmphistos tst.yoda
+    - bash -c '[ -f MC_XS_XS.dat ]' && echo "yoda not empty"
 
 QCDloop:
+  stage: QCDloop
+  extends: .HEJ_compile
   image: hejdock/qcdloopenv
   script:
-  - make -j 8
-  - make test
-  tags:
-  - docker
+    - make test
+
+clean:
+  stage: clean
+  tags: *tags_def
+  image: hejdock/compilerenv
+  script:
+    - cd ..
+    - rm -rf tmp_HEJ
+  when: always