原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢!
原文链接地址:『中级篇』docker之CI/CD持续集成—真实JAVA-Maven项目的CI演示(73)
上次主要说了在githubCI的服务器,并且也演示了github的runner执行CICD,这次通过真实的JAVA-Maven项目来演示下CICD。项目通过gitlab和gitlabCI进行CICD。
源码地址:https://github.com/limingios/gitlabci-maven
源码:https://github.com/limingios/docker/tree/master/No.11
随便找一个开源的JAVA-Maven的在github项目。添加到gitlab上。
maven的环境
sudo gitlab-ci-multi-runner register
# 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
修改.gitlab-ci.yml 就开启了自动构建模式。
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。下次吧!