Search code examples
azure-pipelinesdevopsgithub-actionscicd

what's the use of git checkout action in a cicd pipeline


I've found that in many CICD pipelines such as Azure DevOps pipeline or GitHub action, there is always a checkout branch action. for Azure DevOps pipeline example

  jobs: 
    - job: test
      displayName: Integration Test
      steps:
        - checkout: self
          lfs: true
    ...

for GitHub Action example

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # checkout the repo
    - uses: actions/checkout@master
    - uses: Azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }} 
    ...

What's the use of those checkouts? To clean the branch for the CICD pipeline?


Solution

  • The CI/CD pipeline on GitHub or anywhere else, runs on a special machine called runner. For example, in case of GitHub, runner is a virtual machine hosted by GitHub with the GitHub Actions runner application installed. The ultimate goal of any CI/CD pipeline is to run some commands on the files of your repository. So how does this new machine have the codes/files from your repository ?

    The act of securely copying files from your repository to the runner is called as checking. This is an essential step & is often a primary step (done first). That's why in any CI/CD pipeline, you see that in the first few lines, they checkout the repository.

    More info on GitHub runners is available here.