diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1f2662def9622f31ddd0db90e0e92f6e7d324610..d30a252430f5471e2c90135bc7167f5988034ec8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -34,19 +34,33 @@ before_script:
   - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
   - chmod 644 ~/.ssh/known_hosts
 
+stages:
+  - test
+  - build
+  - deploy
+
 test:cargo:
+  stage: test
   script:
     - rustc --version && cargo --version  # Print version info for debugging
 
-run_test_doc:
+build:codes:
+  stage: build
   script:
     - cd codes
     - ./run_tests.sh
-    - cd ../book
+  
+build:book:
+  stage: build
+  script:
+    - cd book
     - mdbook test
     - mdbook build
 
-run_deploy_book:
+deploy:book:
+  stage: deploy
+  only:
+    - main
   script:
     - cd book
     - mdbook build