一、gitlab-runner 安裝
1.1 、下載執行文件
# Linux x86-64 sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64 # Linux x86 sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-386 # Linux arm sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm
1.2、設置執行權限
sudo chmod +x /usr/local/bin/gitlab-runner
1.3 、創建 GitLab CI 用戶
useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
1.4、運行服務
gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
gitlab-runner start
二、注冊
2.1 獲取 Gitlab 注冊令牌,gitlab地址
打開 gitlab 項目 -> 設置 -> CI / CD -> Runners 設置
2.2、 LINUX 注冊
- 運行注冊
-
sudo gitlab-runner register
-
輸入你的 GitLab URL(上面的gitlab地址)
-
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
http://192.168.182.135:8080/ -
輸入
注冊令牌
來注冊 Runner(上面的注冊令牌) -
Please enter the gitlab-ci token for this runner
1PyJ-5LsbgN9Qow6MXhN -
輸入 Runner 說明(任意)
-
Please enter the gitlab-ci description for this runner [hostame] my-runner
-
輸入 Runner 的 tags(任意)
-
Please enter the gitlab-ci tags for this runner (comma separated): my-tag,another-tag
-
輸入 Runner 執行方式(選擇shell方式)
-
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: shell
-
如果是在 Docker 中運行, you'll be asked for the default image to be used for projects that do not define one in .gitlab-ci.yml:
-
Please enter the Docker image (eg. ruby:2.1): alpine:latest
三、 鏈接成功
四、 編寫 .gitlab-ci.yml
集成
image: java:8 stages: - build - build-pro #測試環境 build: stage: build script: - pwd - cd project/my_app - /usr/local/maven/bin/mvn clean package -P test - sh /usr/local/project_deploy_script/app/app_test.sh tags: - deploy-app only: - develop #正式環境 stage: build-pro script: - pwd - cd project/my_app - /usr/local/maven/bin/mvn clean package -P pro - sh /usr/local/project_deploy_script/app/app.sh tags: - deploy-app only: - master
五、執行集成
- 下次提交代碼就會走集成任務了