Skip to content
Expert CI/CDLesson 5 of 5 2 min read

Deploying from a Pipeline

Turning a green build into a release: artifacts, environments, and shipping code out over SSH.

On this page4 sections

Build and test stages prove the code works. The deploy stage is where it actually starts running somewhere real - and where mistakes are the most expensive, so it deserves its own habits.

Build once, promote everywhere

A common mistake: rebuilding the application separately for dev, staging, and production. That means three different builds, and no real guarantee they're identical.

The fix: build one artifact (a jar, a Docker image, a zip of static assets), and promote that exact same artifact through each environment:

build → artifact.zip → deploy to dev → deploy to staging → deploy to prod

If it passed staging, production is getting the literal bytes that were tested - not a "should be the same" rebuild.

Common deploy steps

A deploy stage in a Jenkinsfile is usually just shell commands wired up to move that artifact somewhere and restart a service:

groovy
stage('Deploy') {
  steps {
    sh 'scp build/app.jar deploy@prod-server:/opt/app/'
    sh 'ssh deploy@prod-server "systemctl restart app"'
  }
}

rsync is a frequent upgrade over plain scp for anything bigger than a single file, since it only transfers what actually changed.

Rollback is part of the plan, not an afterthought

The deploy stage that matters most is the one that hasn't failed yet. Keep the previous artifact around, and know exactly how you'd restore it:

  • Re-deploy the last-known-good artifact.
  • Or keep two environments ("blue" and "green") and just flip which one receives traffic.

A deploy step without a rollback plan isn't really a safety net - it's a bet.

Try it

Run these in the practice terminal (opens in a new tab). It opens in a new tab, so you keep your place here.
bash
ssh deploy@prod-server

When you're ready, hit Mark complete and move to the next lesson.

Challenge

Connect to the production deploy target over SSH as the deploy user.

Want to experiment first? Try things in the practice terminal (opens in a new tab), then enter the command that solves the task here.

Quiz

Lock in the concepts. Score at least 80% to mark the lesson complete.

0 of 2 answered

Done with this one?

Skipped the challenge? You can mark the lesson complete by hand.

Your notes

Kept on this browser only.