Opscraft
Jenkinsfile · Lesson 6 of 10 · 3 min read

Approvals and promotion

The input directive (preferred) vs input step

stage('Approve production') {
  agent none                                          // no executor held while waiting
  when { branch 'main'; beforeInput true }
  options { timeout(time: 24, unit: 'HOURS') }        // auto-abort if nobody approves
  input {
    message 'Deploy orders to production?'
    ok 'Deploy'
    submitter 'release-managers,platform-leads'       // users or groups allowed to approve
    parameters { string(name: 'CHANGE_TICKET', description: 'Change request ID') }
  }
  steps { echo "Approved with ticket ${CHANGE_TICKET}" }
}

Why these details matter:

Enlarge diagramStaging OKsmoke testspassedApproveproductionagent none ·timeout 24 hsubmitterrelease-managersonlyPromotesame image tag toprod
Figure 1. A safe approval stage: no agent while waiting, a timeout, and only named groups may approve.
Swipe sideways to see all of it, or tap to open it full screen.
  • Don't hold an executor or pod while waiting for a human — agent none on the approval stage (the stage-level input directive is evaluated before the agent is allocated). Waiting inside a pod agent can keep a pod running for hours.
  • Timeout so abandoned approvals don't pile up.
  • submitter restricts who can approve — combine with folder permissions so people can't edit the Jenkinsfile to remove it (and protect the main branch).
  • milestone before/after the approval ensures an older build waiting for approval can't deploy after a newer one.

Promotion in a GitOps world

Instead of Jenkins running kubectl apply against production, the "deploy" stage updates the environment's Git config (e.g. a Kustomize overlay) and Flux applies it:

stage('Promote to staging') {
  agent { kubernetes { yamlFile 'ci/pod-tools.yaml'; defaultContainer 'tools' } }
  when { branch 'main' }
  steps {
    withCredentials([sshUserPrivateKey(credentialsId: 'gitops-deploy-key', keyFileVariable: 'KEY')]) {
      sh '''
        export GIT_SSH_COMMAND="ssh -i $KEY -o StrictHostKeyChecking=accept-new"
        git clone [email protected]:acme/platform-gitops.git gitops
        cd gitops/apps/orders/overlays/staging
        kustomize edit set image orders=$REGISTRY/orders:$GIT_COMMIT
        git -c user.name=jenkins -c [email protected] commit -am "orders: staging -> $GIT_COMMIT"
        git push origin HEAD:main
      '''
    }
  }
}

Production promotion is the same change to the prod overlay — ideally via a pull request that's reviewed, giving an audit trail for free.

Enlarge diagramJenkins stageclone the GitOps repokustomize editset imageorders:<sha>commit + pushstaging overlayFluxsees the commit,applies it1234For production, open a pull request to the prod overlay instead: review and audit trail for free.
Figure 2. Promotion in a GitOps world: the deploy stage only edits Git; Flux, inside the cluster, applies the change.
Swipe sideways to see all of it, or tap to open it full screen.