记快乐符号:
    在centos7服务器命令安装gitlab runner
    1、选择你需要的版本 uname -a

    1. https://gitlab-runner-downloads.s3.amazonaws.com/latest/index.html

    2、下载选择版本内容

    1. wget https://gitlab-runner-downloads.s3.amazonaws.com/latest/rpm/gitlab-runner_amd64.rpm

    3、rpm安装服务 你会发现错误 这个时候请安装 git 服务

    1. rpm -i gitlab-runner_amd64.rpm

    4、rpm更新服务

    1. rpm -Uvh gitlab-runner_<arch>.rpm

    5、安装git 服务继续第四步

    1. yum install git

    6、开始注册runner

    1. gitlab-runner register

    7、gitlab页面操作该地址以及token
    image.png
    8、开始注册runnner

    1. gitlab-runner register

    image.png

    1. Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
    2. https://gitlab.com(输入GitLab实例URL)
    3. Please enter the gitlab-ci token for this runner
    4. xxx(输入runner注册令牌)
    5. Please enter the gitlab-ci tags for this runner (comma separated):
    6. my-tag(输入runner标签 可在gitlabUI页面修改)
    7. Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
    8. docker(输入runner脚本执行环境根据自身选择
    9. Enter the default Docker image (for example, ruby:2.6):
    10. app

    9、此时最好是把 宿主机的docker 执行权限配置给 runner

    1. /etc/gitlab-runner/config.toml

    10、找到配置runners.docker 修改配置 前面路径为宿主机目录 后面为内部路径

    1. volumes = [
    2. "/cache",
    3. "/usr/local/bin/docker:/usr/local/bin/docker:ro",
    4. "/var/run/docker.sock:/var/run/docker.sock:rw"
    5. ]

    11、重启服务

    1. systemctl restart gitlab-runner

    12、上传项目并在项目根目录添加文件 .gitlab-ci.yml

    1. image: circleci/jdk8:0.1.1
    2. variables:
    3. DOCKER_DRIVER: overlay2
    4. DOCKER_TLS_CERTDIR: ''
    5. stages:
    6. - test
    7. test:
    8. stage: test
    9. script:
    10. - ls
    11. - pwd
    12. - java -version

    13、测试needs流水线写法

    1. image: circleci/jdk8:0.1.1
    2. variables:
    3. DOCKER_DRIVER: overlay2
    4. DOCKER_TLS_CERTDIR: ''
    5. stages:
    6. - build
    7. - test
    8. - deploy
    9. # test:
    10. # stage: test
    11. # script:
    12. # - ls
    13. # - pwd
    14. # - java -version
    15. linux:build:
    16. stage: build
    17. script: echo "Building linux..."
    18. mac:build:
    19. stage: build
    20. script: echo "Building mac..."
    21. lint:
    22. stage: test
    23. needs: []
    24. script: echo "Linting..."
    25. linux:rspec:
    26. stage: test
    27. needs: ["linux:build"]
    28. script: echo "Running rspec on linux..."
    29. linux:rubocop:
    30. stage: test
    31. needs: ["linux:build"]
    32. script: echo "Running rubocop on linux..."
    33. mac:rspec:
    34. stage: test
    35. needs: ["mac:build"]
    36. script: echo "Running rspec on mac..."
    37. mac:rubocop:
    38. stage: test
    39. needs: ["mac:build"]
    40. script: echo "Running rubocop on mac..."
    41. production:
    42. stage: deploy
    43. script: echo "Running production..."

    14、查看项目CI/CD流水线 完成后大功告成
    15、新问题 默认runner 单线程执行所以修改参数配置

    1. concurrent = 1