diff --git a/.Rbuildignore b/.Rbuildignore
index 833904795d48f860294fff4bee09c098eeb9133f..0989b16dd699b1609e751ffd6370e349f4d11815 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -1,4 +1,5 @@
 ^.*\.Rproj$
 ^\.Rproj\.user$
-^packrat/
 ^\.Rprofile$
+^packrat/
+^\.gitlab-ci.yml$
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..fac51d2895add908ff7870ffa8aca87930b70cea
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,99 @@
+stages:
+  - update_packages
+  - build
+  - tests
+
+default:
+  before_script:
+    - echo "setwd(\"$(pwd)\")" > .Rprofile
+    - PATH=~/R/sources/R-${R_VERSION}/bin:$PATH
+    - rename "s/${R_VERSION}.airGRteaching/airGRteaching/" *.tar.gz
+    - R -e 'chooseCRANmirror(graphics = FALSE, ind = 1); pkg <- c("dygraphs", "plotrix", "shiny", "shinyjs"); pkgInst <- installed.packages()[, "Package"]; pkgMiss <- setdiff(pkg, pkgInst); if (length(pkgMiss) > 0) install.packages(pkgMiss)'
+
+.update_packages:
+  stage: update_packages
+  only:
+    refs:
+      - tags
+      - schedules
+  script:
+    - Rscript -e "update.packages(ask=FALSE, repos=\"http://cran.r-project.org\")"
+
+.build:
+  stage: build
+  script:
+    - cd ..
+    - echo "setwd(\"$(pwd)\")" > .Rprofile
+    - R CMD build airgrteaching
+    - rename "s/airGRteaching/${R_VERSION}.airGRteaching/" airGRteaching_*.tar.gz
+    - mv *.tar.gz airgrteaching/
+  artifacts:
+    untracked: true
+    expire_in: 1 week
+
+.check_as_cran:
+  stage: tests
+  script:
+    - R CMD check --as-cran airGRteaching_*.tar.gz
+
+update_packages_patched:
+  variables:
+    R_VERSION: "patched"
+  extends: .update_packages
+
+update_packages_devel:
+  variables:
+    R_VERSION: "devel"
+  extends: .update_packages
+
+update_packages_oldrel:
+  variables:
+    R_VERSION: "oldrel"
+  extends: .update_packages
+
+build_patched:
+  variables:
+    R_VERSION: "patched"
+  extends: .build
+
+build_devel:
+  only:
+    refs:
+      - tags
+      - schedules
+  variables:
+    R_VERSION: "devel"
+  extends: .build
+
+build_oldrel:
+  only:
+    refs:
+      - tags
+      - schedules
+  variables:
+    R_VERSION: "oldrel"
+  extends: .build
+
+check_as_cran_patched:
+  variables:
+    R_VERSION: "patched"
+  extends: .check_as_cran
+
+check_as_cran_devel:
+  only:
+    refs:
+      - tags
+      - schedules
+  variables:
+    R_VERSION: "devel"
+  extends: .check_as_cran
+
+check_as_cran_oldrel:
+  only:
+    refs:
+      - tags
+      - schedules
+  variables:
+    R_VERSION: "oldrel"
+  extends: .check_as_cran
+