Setting up Jenkins, GitLab CI, and GitHub Actions
Introduction to Git and GitHub
Git is a distributed version control system that tracks changes to code, allowing multiple developers to collaborate efficiently.
GitHub is a cloud-based platform that hosts Git repositories and adds features like collaboration tools, issue tracking, and CI/CD integration.
Key Concepts:
- Repository (repo): A project folder tracked by Git.
- Commit: A snapshot of changes.
- Clone: Copying a repository locally.
- Push/Pull: Sending/pulling changes between local and remote repos.
Branching, Merging, and Pull Requests
Branching allows developers to work on features or bug fixes in isolation from the main codebase.
main(ormaster) branch: Stable production-ready code.- Feature branches: Used for new development.
Merging integrates changes from one branch into another.
- Fast-forward merge: No divergence; branch simply moves forward.
- Three-way merge: Combines divergent changes, may require conflict resolution.
Pull Requests (PRs) are a GitHub feature for reviewing and discussing proposed changes before merging.
3. Managing Repositories and Workflows
Effective repository management ensures smooth collaboration:
- Repository structure: Organize code, docs, configs.
- Access control: Grant permissions appropriately (read/write/admin).
- Workflow models:
- Git Flow: Main, develop, feature, release, hotfix branches.
- GitHub Flow: Main + feature branches, simplified for continuous deployment.
4. Best Practices in Source Code Management
- Commit often with meaningful messages.
- Keep branches focused on one feature/bug.
- Regularly pull updates from the main branch to avoid conflicts.
- Use
.gitignoreto exclude unnecessary files. - Review code via pull requests before merging.
- Tag releases for versioning.
5. What is CI and Why It Matters
Continuous Integration (CI) is a development practice where code changes are automatically built, tested, and validated before integration into the main branch.
Why CI Matters:
- Detects bugs early.
- Ensures code quality through automated testing.
- Reduces integration headaches.
- Facilitates faster release cycles.
6. Setting up Jenkins, GitLab CI, and GitHub Actions
- Jenkins: Self-hosted automation server. Uses pipelines defined in
Jenkinsfile. - GitLab CI: Built-in CI/CD for GitLab repositories. Uses
.gitlab-ci.yml. - GitHub Actions: Native CI/CD for GitHub repos. Uses workflows in
.github/workflows/*.yml.
Steps to set up CI/CD:
- Define jobs: Build, test, deploy.
- Configure triggers: On push, pull request, or schedule.
- Monitor pipeline results and fix failing jobs.