『中級篇』docker之CI/CD持續整合—真實JAVA-Maven專案的CI演示(73)
阿新 • • 發佈:2018-12-14
隨便找一個開源的JAVA-Maven的在github專案。新增到gitlab上。
copy到gitlab上
-
new project
-
Git repository URL
- 點選create project
runner管理新的gitlabci-maven
maven的環境
sudo gitlab-ci-multi-runner register
新建github-ci 檔案
# These are the default stages. You don't need to explicitly define them. But you could define any stages you need.
stages:
- build
- test
- deploy
# This is the name of the job. You can choose it freely.
maven_build:
# A job is always executed within a stage. If no stage is set, it defaults to 'test'
stage: test
# Since we require Maven for this job, we can restrict the job to runners with a certain tag. Of course, we need to configure a runner with the tag maven with a maven installation
tags:
- maven
# Here you can execute arbitrate terminal commands.
# If any of the commands returns a non zero exit code the job fails
script:
- echo "Building project with maven"
- mvn verify
開始CI操作
修改.gitlab-ci.yml 就開啟了自動構建模式。
- 報錯了。 跟python當初構建的時候一樣。
Running with gitlab-ci-multi-runner 9.5.1 ( 96b34cc)
on maven (e6c8a28d)
Using Docker executor with image maven:latest ...
Using docker image sha256:c4ef2f017e30bbabddf847a3f458985e55ccc24a2be7dbdf72dc032e7bece3e5 for predefined container...
Pulling docker image maven:latest ...
Using docker image maven:latest ID=sha256:1361ae58b0a463172267a0622430ad5f4f8108c4d4b7b1ae7d552e367cf92413 for build container...
Running on runner-e6c8a28d-project-3-concurrent-0 via gitlab-ci...
Cloning repository...
Cloning into '/builds/root/gitlabci-maven'...
fatal: unable to access 'http://gitlab-ci-token:[email protected]/root/gitlabci-maven.git/': Couldn't resolve host 'gitlab.example.com'
ERROR: Job failed: exit code 1
Runner啟動的docker容器裡無法訪問到
gitlab.example.com
這個地址(能訪問到才怪)。這一般是由於我們的測試環境沒有使用域名導致的,gitlab論壇裡也不少人討論這個問題,如果你是在部署正式的gitlab環境,那你自然會有一個域名來使用。不過我這裡只是搭建測試環境,所以我使用了一種投機的方法:
修改Runner的/etc/gitlab-runner/config.toml
檔案,在其中的[runner.docker]
下增加:
sudo vi /etc/gitlab-runner/config.toml
成功了 重新Retry
6666 美滋滋,當初懟了個python現在java遇到這個問題知道咋解決了。
用的不是阿里雲,可能比較慢,不過是演示,之後想想辦法直接在腳本里面配置下私有庫的地址。
PS:這次主要給大家簡單的介紹下CI,還沒設計到CD。下次吧!