What you’ll learn

  • Validate static HTML without compiling it.
  • Gate deployment on validation.
  • Deploy static files to Amazon S3.
  • Handle AWS credentials without committing secrets.

When you’re finished

  • Run the site validator.
  • Prove a failed validation blocks deployment.
  • Deploy the intended files to S3.

Repository: jenkins-static-site-demo

Goal:

GitHub → Jenkins → Validate → Deploy to S3

4.1 Create the static site

Create and clone:

git clone "https://github.com/<GITHUB-USER>/jenkins-static-site-demo.git"
cd jenkins-static-site-demo

Recommended layout:

jenkins-static-site-demo/
├── site/
│   ├── index.html
│   └── styles.css
├── scripts/
│   └── Test-StaticSite.ps1
├── Jenkinsfile
└── README.md

Minimal page:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Jenkins Static Site Demo</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <main>
        <h1>Hello, world!</h1>
        <p>This page was deployed by Jenkins.</p>
    </main>
</body>
</html>

4.2 Validate the site

Static HTML does not need compilation, but Jenkins can still enforce quality gates.

The supplied PowerShell validation script checks:

  • site/index.html exists,
  • it is not empty,
  • it contains an HTML element,
  • it contains a title,
  • it contains the expected heading text,
  • referenced local stylesheet files exist.

Run it locally:

pwsh -File .\scripts\Test-StaticSite.ps1

If you use Windows PowerShell 5.1 instead:

powershell.exe -NoProfile -File .\scripts\Test-StaticSite.ps1

The complete script is in Appendix B.

4.2.1 Validation checkpoint

Before AWS is introduced:

  • index.html exists;
  • validation passes locally;
  • deliberately breaking the expected heading causes validation to fail;
  • restoring the heading returns validation to PASS.

4.3 Configure AWS safely

Do not put AWS access keys in:

  • Jenkinsfile
  • .ps1 files
  • environment files committed to Git
  • README examples containing real values

Credential maturity for this guide:

Do not do:
Hard-coded AWS access keys in source

Beginner lab:
Jenkins Credentials / securely injected runtime values

More production-like:
Short-lived credentials and AWS IAM roles where practical

For a beginner lab, Jenkins Credentials can securely store values and expose them only while the pipeline needs them.

For a more production-like Jenkins controller running inside AWS, prefer short-lived credentials and IAM roles where practical.

Minimum S3 permissions should be scoped to the specific demo bucket rather than your entire AWS account.

4.4 Deploy to S3

The basic AWS CLI syntax is:

aws s3 sync <SOURCE> <TARGET> [OPTIONS]

Example:

aws s3 sync .\site "s3://<BUCKET-NAME>" --delete

4.4.1 Parameters

Value Required? Meaning
.\site Yes Local source directory
s3://<BUCKET-NAME> Yes S3 destination
--delete Optional Remove destination objects that no longer exist locally

--delete is useful for exact mirroring but is also destructive. Understand the target bucket/prefix before enabling it.

A safer first deployment can omit it:

aws s3 sync .\site "s3://<BUCKET-NAME>"

4.4.2 Jenkins deployment rule

The deploy stage comes after validation:

Validate PASS → Deploy
Validate FAIL → Stop

Optional CloudFront can be added later. Keep the first S3 lab simple.

4.5 Deployment gate lab

Break the HTML:

  1. Remove the required <h1>Hello, world!</h1> text.
  2. Commit and push.
  3. Run Jenkins.
  4. Confirm validation fails.
  5. Confirm the S3 deploy stage does not execute.
  6. Fix the page.
  7. Commit and push.
  8. Confirm validation and deployment both pass.

This is the core CD lesson: bad input should not reach the deployment step.

Chapter checkpoint

Confirm:

  • static-site validation passes;
  • a deliberate validation failure prevents deployment;
  • AWS authentication is external to source control;
  • successful pipeline copies the expected files to the intended S3 bucket/prefix;
  • no real credential values appear in Git history or Jenkins console output.