持续集成与持续部署(六)01-CircleCI——使用简介-持续集成工具 & config.yml完整配置
CircleCI
使用简介
-
注册 CircleCI
打开 CircleCI 官方网站,使用您的GitHub帐户登录。
进行授权:
- 启动存储库
检查要在 CircleCI 上管理的存储库的开关按钮。
-
编写 config.yml
version: 2 jobs: build: docker: ... branches: ... steps: ... environment: ...
官方参考文档:https://circleci.com/docs/2.0/configuration-reference/#version
config.yml配置
来看一个完事版的配置
version: 2 jobs: build: docker: - image: ubuntu:14.04 - image: mongo:2.6.8 command: [mongod, --smallfiles] - image: postgres:9.4.1 # some containers require setting environment variables environment: POSTGRES_USER: root - image: redis@sha256:54057dd7e125ca41afe526a877e8bd35ec2cdd33b9217e022ed37bdcf7d09673 - image: rabbitmq:3.5.4 environment: TEST_REPORTS: /tmp/test-reports working_directory: ~/my-project steps: - checkout - run: command: echo 127.0.0.1 devhost | sudo tee -a /etc/hosts # Create Postgres users and database # Note the YAML heredoc '|' for nicer formatting - run: | sudo -u root createuser -h localhost --superuser ubuntu && sudo createdb -h localhost test_db - restore_cache: keys: - v1-my-project-{{ checksum "project.clj" }} - v1-my-project- - run: environment: SSH_TARGET: "localhost" TEST_ENV: "linux" command: | set -xu mkdir -p ${TEST_REPORTS} run-tests.sh cp out/tests/*.xml ${TEST_REPORTS} - run: | set -xu mkdir -p /tmp/artifacts create_jars.sh ${CIRCLE_BUILD_NUM} cp *.jar /tmp/artifacts - save_cache: key: v1-my-project-{{ checksum "project.clj" }} paths: - ~/.m2 # Save artifacts - store_artifacts: path: /tmp/artifacts destination: build # Upload test results - store_test_results: path: /tmp/test-reports deploy-stage: docker: - image: ubuntu:14.04 working_directory: /tmp/my-project steps: - run: name: Deploy if tests pass and branch is Staging command: ansible-playbook site.yml -i staging deploy-prod: docker: - image: ubuntu:14.04 working_directory: /tmp/my-project steps: - run: name: Deploy if tests pass and branch is Master command: ansible-playbook site.yml -i production workflows: version: 2 build-deploy: jobs: - build: filters: branches: ignore: - develop - /feature-.*/ - deploy-stage: requires: - build filters: branches: only: staging - deploy-prod: requires: - build filters: branches: only: master
-
设置/查看任务