Ravindra BagaleCourses & study guides मराठी

Chapter 8: CI/CD Concepts

DevOps

8.6 Manual approval for production — when and why

Why: the problem

A bank app team at TCS ships to production every Thursday. The bank has a rule: a named person must say yes before any change reaches real customers. This is not because they distrust the pipeline. It is because of law and audit. If something goes wrong, the bank must show who approved it and when. Other teams, like Netflix, ship automatically all day with no human button. Both are right for their world. A manual approval is a pause in the pipeline. The pipeline builds and tests, deploys to staging, then waits. A reviewer looks at staging and clicks Approve. Only then does the deploy to production start. Use it when the risk is high or the law asks for it. Do not use it everywhere, or people will click Approve without looking, which is worse than no button.

What we will build

You will add a manual approval step before the production deploy of the badge API in GitHub Actions (environment reviewers), GitLab CI (when: manual and protected environments) and Jenkins (input step). You will also make the approval leave an audit record: who, when and which version.

What: every term in plain English

  • Manual approval — A pause in the pipeline that waits for a named person to click Approve.
  • Reviewer or approver — The person allowed to approve. Often a lead or release manager.
  • Audit trail — A record of who approved which version and when.
  • Protected environment — An environment where only some people can deploy or approve.
  • Deployment window — Times when prod deploys are allowed, like weekdays 10 a.m. to 4 p.m.
  • Separation of duties — The person who wrote the code is not the one who approves it.
  • Timeout for approval — If nobody approves in time, the run ends instead of waiting forever.
Make the production environment Add required reviewers Block self-approval Allow only main Push and watch the wait Approve
Build, staging, pause for a named approver, then production

How: step by step

  1. Make the production environment

    Repo Settings > Environments > New environment > production
    

    What it does: A place to attach rules.

    Output

    Environment "production" created
    
  2. Add required reviewers

    production > Required reviewers > add ravi-lead
    

    What it does: Now deploy jobs to production must wait for this person.

    Output

    1 required reviewer
    
  3. Block self-approval

    Tick "Prevent self-review"
    

    What it does: The person who pushed cannot approve their own deploy.

    Output

    Prevent self-review: on
    
  4. Allow only main

    Deployment branches > Selected branches > main
    

    What it does: Feature branches can never deploy to prod.

    Output

    main
    
  5. Push and watch the wait

    git push origin main
    

    What it does: The pipeline goes to staging, then shows "Waiting for review".

    Output

    deploy-prod  waiting
    
  6. Approve

    Open the run > Review deployments > tick production > Approve and deploy
    

    What it does: The deploy job starts. The approval is logged.

    Output

    Approved by ravi-lead
    

Example 1: Approval through environment reviewers (GitHub Actions)

Stack. GitHub Actions

Goal. Approval through environment reviewers (GitHub Actions).

.github/workflows/cicd.yml (prod job)

deploy-prod:
  needs: deploy-staging
  runs-on: ubuntu-latest
  environment:
    name: production
    url: https://badge.example.com
  steps:
    - run: echo "Approved by ${{ github.triggering_actor }} for ${{ github.sha }}"
    - run: ./deploy.sh prod ${{ github.sha }}
    - run: curl -fsS https://badge.example.com/health

What each line does

  • environment: name: production — This one line connects the job to the reviewer rule you set in Settings.
  • No approval code in YAML — The pause comes from the environment rule, not from a step.
  • github.triggering_actor — Prints who started the run, for the log.
  • curl -fsS — Smoke test after deploy.

Green output

deploy-staging  succeeded
deploy-prod     Waiting for review: production needs approval from ravi-lead
... ravi-lead approved ...
deploy-prod     succeeded  {"env":"prod","status":"ok"}

Expected result. The run page and the environment history both show who approved and when.

Example 2: A manual job in GitLab CI with a protected environment

Stack. GitLab CI

Goal. A manual job in GitLab CI with a protected environment.

.gitlab-ci.yml (prod job)

deploy-prod:
  stage: deploy
  needs: [deploy-staging]
  environment:
    name: production
    url: https://badge.example.com
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
      when: manual
  allow_failure: false
  script:
    - echo "deploy $CI_COMMIT_SHORT_SHA by $GITLAB_USER_LOGIN"
    - ./deploy.sh prod "$CI_COMMIT_SHORT_SHA"

What each line does

  • when: manual — The job shows a play button and waits for a click.
  • allow_failure: false — The pipeline shows as blocked, not passed, until someone runs it.
  • $GITLAB_USER_LOGIN — Who clicked play. Saved in the log.
  • Protected environment — Settings > CI/CD > Protected environments > production > Allowed to deploy: Maintainers.

Green output

deploy-staging  passed
deploy-prod     manual   (play button)
$ echo "deploy a3f2c1d by ravi.lead"
deploy a3f2c1d by ravi.lead
Job succeeded

Expected result. Only maintainers see the play button. The environment page lists every deploy with the user name.

Example 3: The input step in Jenkins, with a timeout

Stack. Jenkins

Goal. The input step in Jenkins, with a timeout.

Jenkinsfile (prod part)

stage('Approve prod') {
    when { branch 'main' }
    steps {
        timeout(time: 2, unit: 'HOURS') {
            input message: "Deploy ${env.GIT_COMMIT.take(7)} to production?",
                  ok: 'Deploy',
                  submitter: 'release-managers',
                  submitterParameter: 'APPROVER'
        }
    }
}
stage('Deploy prod') {
    when { branch 'main' }
    steps {
        sh './deploy.sh prod $GIT_COMMIT'
    }
}

What each line does

  • input message: — Jenkins pauses and shows a box with Deploy and Abort.
  • submitter: 'release-managers' — Only this group can click Deploy.
  • submitterParameter — Saves the approver name in a variable for the log.
  • timeout(time: 2, unit: HOURS) — If nobody clicks in 2 hours, the build is aborted, not left hanging.
  • agent note — Put input outside a heavy agent block so it does not hold an executor while waiting.

Green output

[Pipeline] { (Approve prod)
[Pipeline] input
Deploy a3f2c1d to production?
Deploy or Abort
Approved by ravi.lead
[Pipeline] { (Deploy prod)
+ ./deploy.sh prod a3f2c1d
Finished: SUCCESS

Expected result. The build log says who approved. That line is your audit record.

Verify: did it work?

  1. Check the audit record

    Open Environments > production > deployment history
    

    What it does: Each row shows version, time and approver.

    Output

    a3f2c1d  25 Oct 2026 11:40  approved by ravi-lead
    
  2. Check self-approval is blocked

    Push yourself and try to approve
    

    What it does: The Approve button must be grey for you.

    Output

    You cannot approve your own deployment
    

When it is red 1

Waiting for review... (for days)

Cause. Nobody is set as reviewer, or the reviewer did not get the notice.

Fix, step by step

  1. Check Settings > Environments > production > Required reviewers.
  2. Add a team, not one person, so someone is always there.
  3. Add a timeout so old runs end.

When it is red 2

Rejected by ravi-lead

Cause. The reviewer clicked Reject after looking at staging.

Fix, step by step

  1. Read the comment the reviewer left.
  2. Fix the issue, push again.
  3. The new commit goes through staging and approval again.

When it is red 3

Branch "feature/x" is not allowed to deploy to production due to environment protection rules.

Cause. Someone tried to deploy prod from a feature branch.

Fix, step by step

  1. Merge to main through a pull request.
  2. Deploy from main only.

Cleanup

  1. Nothing to clean

    echo "approvals are kept as audit history"
    

    What it does: Do not delete deploy history. Auditors need it.

    Output

    approvals are kept as audit history
    

Ravindra Bagale's Tip

Trust the approve button, but do not put it on every change. Otherwise people approve without looking. Keep that in mind!

Practice tasks

Easy Find the approval in history

Why: Read an audit record.

What to do: Open the environment history after an approved deploy.

How:
  1. Note who and when.

Check: You can name the approver.

Medium Reject on purpose

Why: Know the reject path.

What to do: Ask your reviewer to reject a deploy.

How:
  1. Read the comment.
  2. Push a fix.

Check: The second run is approved.

Hard Add a deploy window

Why: Stop Friday night deploys.

What to do: Add a check that fails the prod job outside 10:00 to 16:00 IST on weekdays.

How:
  1. Use date +%u and date +%H in a script.

Check: A run outside the window fails with a clear message.

Easy Say manual approval for production in two lines

Why: If you can say it simply, you understand it. Juniors and interviewers both want the short version first.

What to do: Write two short lines about manual approval for production for a fresher who knows only Linux, Git and Docker basics.

How:
  1. Write the problem it solves.
  2. Write the one pipeline line or command you use for it.
  3. Read it aloud to a friend.

Check: A fresher understands it without asking a question.

Easy Keep a throwaway lab repo

Why: Practice needs a repo you can break. If it gets messy, you delete it and start again.

What to do: Make a small practice repo called badge-api with one Python file, one test and one Dockerfile.

How:
  1. mkdir badge-api and cd into it
  2. git init -b main
  3. Add app.py, test_app.py and Dockerfile from this chapter, then commit.

Check: git log shows one commit and pytest prints 1 passed.

Medium Do it in a second CI tool

Why: CI/CD is the idea. The tool is only the syntax. The same stages must work in GitHub Actions, GitLab CI and Jenkins.

What to do: Write the pipeline from this lesson in a second CI tool.

How:
  1. If you used GitHub Actions, write .gitlab-ci.yml or a Jenkinsfile now.
  2. Keep the same stage names and the same commands.
  3. Only the wrapper syntax should change.

Check: Same green result, same stage names, different tool.

Medium Break it on purpose

Why: You must know the red log by face. In a real outage there is no time to read slowly.

What to do: Cause one error from the "When it is red" part of this lesson and fix it.

How:
  1. Follow the error section.
  2. Copy the exact red line from the job log into your notes.
  3. Write the fix in one line.

Check: You fixed it using only the steps, without searching the web.

Medium Write a one-page runbook

Why: At 2 a.m. nobody remembers pipeline menus. A short page saves the on-call person.

What to do: Write a one-page runbook for this lesson.

How:
  1. Title, when to use, exact steps or pipeline lines, how to check, how to undo.

Check: A teammate can follow it alone.

Hard Explain it like an interview

Why: Interviewers want real stories, not definitions.

What to do: Record a 60 second answer about this lesson.

How:
  1. Say the problem, the pipeline lines you wrote, and one error you hit.

Check: Your answer has a real pipeline line and a real error message.

Hard Draw the flow top to bottom

Why: A drawing shows the order of work and which stage waits for which.

What to do: Draw this lesson as boxes from top to bottom.

How:
  1. Start at git push, go through each stage, end at the green run or the deployed app.

Check: Each box matches a real line in your job log.

Homework: try at home

Try at home

At home, make a production environment with yourself and a friend as reviewers, turn on prevent self-review, and run one deploy that your friend approves.

Recap

  • Manual approval is a pause before production.
  • Use it when risk or law needs it.
  • Reviewers should not be the authors.
  • Approvals leave an audit trail.
  • Add timeouts and allow only main.

FAQ

Is manual approval against DevOps?

No. Continuous Delivery allows a human button. Continuous Deployment removes it.

Can approval be automatic?

Yes, with checks like error rate after a canary. Many teams move there over time.

Who approves in small teams?

Another developer who did not write the change.

Does approval replace code review?

No. Code review is on the pull request. Approval is on the deploy.

What if the approver is on leave?

Make a team the approver, not one person.

Interview questions

  1. When would you use a manual approval in a pipeline?

    For production deploys in regulated or high risk systems, or where audit needs a named approver.

  2. How do you set approval in GitHub Actions?

    Make a production environment with required reviewers and point the deploy job at it.

  3. How does Jenkins do approvals?

    With the input step, limited by submitter and wrapped in a timeout.

  4. What is separation of duties?

    The author of a change cannot approve its deploy to prod.

  5. What is the risk of too many approvals?

    Approval fatigue: people click yes without looking, and delivery slows down.

Quick quiz

Q1. Why add a manual approval?

For high risk changes or when law and audit ask for it.

Q2. Who should approve?

Someone other than the author, like a lead or release manager.

Q3. What is an audit trail?

A record of who approved which version and when.

Q4. Why add a timeout to approvals?

So runs do not wait forever.

Q5. When is manual approval a bad idea?

When it is on every change and people approve without looking.

Did you understand? Let us try it once more.

Ravi Sir's Cards for this lesson

मराठी cards