Ravindra BagaleCourses & study guides मराठी

Chapter 24: Jenkins with GitHub, GitLab and Bitbucket

Chala mitrano, aaj aapan Git hosts: GitHub, GitLab, Bitbucket — ekach Jenkins idea. HTTPS/SSH credentials, webhook vs poll, Multibranch, PR ani tag builds. Ghabru naka.

What you will learn in this chapter

  • Same Jenkins idea across three Git hosts
  • HTTPS token vs SSH key as credential ids
  • Webhook versus poll when the laptop is offline to the internet
  • Multibranch, PR builds, tag builds, indexing, orphaned items

Concepts in this chapter

  1. 24.1Three hosts, one Jenkins idea
  2. 24.2HTTPS or SSH
  3. 24.3Webhook versus poll — the laptop is not on the internet
  4. 24.4Multibranch
  5. 24.5Pull request builds and tag builds
  6. 24.6Branch indexing and orphaned items
  7. 24.7What not to do

The chapter recap is at the end of the last concept page.

Practice Tasks

About this scenario

Suppose we are on the DevOps team at Toyota, the automobile company, working from Toyota City. Haruto Sato leads the team, and we look after the factory parts tracker. Costs are counted in JPY. In the tasks below we do real DevOps jobs on this project using what this lesson teaches. Toyota is a real company, but this project, the people, servers, IP addresses and numbers are made up for practice.

0 / 12

Easy List branches

Why: You must know which branches exist before you merge or delete.

What to do: List all branches, local and remote.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Easy Create and switch to a branch

Why: Feature work on its own branch keeps main stable.

What to do: Create a new branch feature/factory-parts-cache and switch to it in one command.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Easy Declarative Jenkinsfile: build and test

Why: Pipeline as code lives in Git with the app, so every change is reviewed.

What to do: Write a declarative Jenkinsfile: agent any; stage Build runs sh 'mvn -B package'; stage Test runs sh 'mvn test'.

How:
  1. Start with pipeline { and close it with } at the end.
  2. Add agent, then stages { } with one stage('Name') { steps { } } per step.
  3. Put the commands inside steps using sh '...'.
  4. Count your { and } so every block is closed, then click Check answer.

Medium Deploy only from main

Why: Feature branches are built and tested but never deployed.

What to do: Declarative pipeline, agent any, stage Deploy with when { branch 'main' } and steps sh './deploy.sh ap-northeast-1'.

How:
  1. Start with pipeline { and close it with } at the end.
  2. Add agent, then stages { } with one stage('Name') { steps { } } per step.
  3. Put the commands inside steps using sh '...'.
  4. Count your { and } so every block is closed, then click Check answer.

Medium Delete a merged branch

Why: Old branches clutter the repository and confuse the team.

What to do: Delete the local branch feature/factory-parts-cache, which is already merged.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Medium Merge a feature branch

Why: Merging brings tested feature work into main.

What to do: We are on main. Merge the branch feature/factory-parts-cache into it.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Medium Run only for main and pull requests

Why: Limiting triggers saves CI minutes and noise.

What to do: Write a workflow named Build whose on: runs for push to branch main and for pull_request to branch main. One job build on ubuntu-latest with a single step run: make build.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Use "- " for list items and fill each value from the task.
  4. Check the colons and spacing, then click Check answer.

Medium Nightly scheduled workflow

Why: Nightly runs catch slow-breaking things like expired certificates.

What to do: Workflow that runs on schedule with cron "0 1 * * *". Job scan on ubuntu-latest, step run: ./scan.sh.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Use "- " for list items and fill each value from the task.
  4. Check the colons and spacing, then click Check answer.

Hard Copy one fix to a release branch

Why: A hotfix on main is also needed on the release branch, without the other commits.

What to do: We are on release/1.7.8. Apply only commit 542045e from main here.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Hard Merge with a merge commit

Why: A merge commit keeps a clear record that a feature was merged.

What to do: Merge release/1.7.8 into the current branch and always create a merge commit, even if fast-forward is possible.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Hard Delete a remote branch

Why: After the pull request is merged, the remote branch is no longer needed.

What to do: Delete the branch feature/factory-parts-cache on origin.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Hard Rebase onto main

Why: Rebasing gives a straight, easy-to-read history before a pull request.

What to do: We are on our feature branch. Replay its commits on top of the latest main.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Ravi Sir's Cards: 15 revision, interview and comparison cards for this chapter · मराठी cards