CI/CD with GitLab


  1. create a .gitlab-ci.yml - I usually do this via web interface. An example is included below
  2. brew install gitlab-runner install gitlab runner - can usually be done via package manager on system
  3. gitlab-runner register register gitlab-runner
    1. https://gitlab.com enter the url for gitlab repo. If not self hosting it will just be gitlab.com
    2. <Token> enter the token for repo. Found under Settings > CI/CD > Runners > Set up Specific Runner Manually
    3. Description of project
    4. tagone,tagtwo more on this to come later
  4. gitlab-runner start
  5. gitlab-runner status
    • if status does not show running, need to troubleshoot. On Mac check logs via syslog
  6. Now when you make commits that match the given tags or branches the commands in .gitlab-ci.yml will run
  • Notes
    • Without configuring the runner it will create a build directory in project root so ensure that is added to .gitignore
.gitlab-ci.yml
deploy_stage:
    stage: deploy
    environment: Staging
    only:
        - development
    script:
        - rm -rf /Users/kwilliams/Documents/Development/
        - mkdir -p /Users/kwilliams/Documents/Development
        - ls > /Users/kwilliams/ls.txt
        - mv ./* /Users/kwilliams/Documents/Development
        
deploy_production:
    stage: deploy
    environment: Production
    only:
        - master
    script:
        - rm -rf /Users/kwilliams/Documents/Deployed
        - mkdir -p /Users/kwilliams/Documents/Deployed
        - mv ./* /Users/kwilliams/Documents/Deployed