Ravindra BagaleCourses & study guides Track your progress
AI CODING · 100% AI, NO HURDLES

Jenkins Pipeline 100% Done by Claude: From One EC2 to a Working Pipeline

You launch one empty server. After that, Claude does everything — install, settings, plugins, and a running pipeline — over SSH, from inside VS Code. You just approve each step.

In short: start one EC2, open VS Code with Claude Code, give Claude your key file and the server IP, and let it build the whole Jenkins pipeline. You stay in control by approving each command.

Why do it this way

WHY

Setting up Jenkins by hand has many small steps. It is easy to miss one. Letting Claude run the steps over SSH is fast and repeatable. You read each command before it runs, so you learn and stay safe.

What these words mean

WHAT
  • EC2: one rented Linux server on AWS (Amazon Web Services).
  • SSH: a safe way to run commands on a far server from your computer.
  • .pem key: a secret file that proves it is you when you SSH. Keep it private.
  • Claude Code: Anthropic's coding tool. It runs as a VS Code extension (a chat panel) and also as a CLI (a claude command in the terminal).
  • Jenkins: a free tool that builds and tests your code automatically (CI/CD).
  • Docker: a tool that runs apps in small boxes called containers.

The whole flow, top to bottom

1 · Launch one EC2 the only manual step 2 · Open VS Code + Claude Code extension or CLI 3 · Give key file + IP ~/Downloads/mykey.pem, 3.3.3.3 4 · Claude works over SSH installs Jenkins, Docker, plugins 5 · Pipeline is running job built from your Jenkinsfile

Setup — VS Code with Claude Code

SETUP · INSTALL

You need VS Code 1.94 or later and a paid Claude plan (Pro, Max, Team or Enterprise) or a Claude Console account. No API key is needed; you sign in.

  1. Install the extension. In VS Code press Ctrl+Shift+X, search "Claude Code", click Install. Click the Spark icon to open the panel and sign in.
  2. Install the CLI too (for the terminal). macOS/Linux/WSL: curl -fsSL https://claude.ai/install.sh | bash. Windows PowerShell: irm https://claude.ai/install.ps1 | iex. The extension does not add claude to your PATH, so this separate install lets you run claude in the integrated terminal.
  3. Open your project folder in VS Code, open the terminal with Ctrl+`, and run claude to start a session.
Settings / config: for the optional "launch EC2 with Claude" part you also need the AWS CLI installed and aws configure done once with your access key, secret and region. For the SSH part you only need your .pem key file on your computer.

Step 1 (the only manual step): launch one EC2

HOW
  1. Open the AWS Console → EC2 → Launch instance.
  2. Choose Amazon Linux 2023, size t3.small (enough for Jenkins + Docker).
  3. Create or pick a key pair. Download the .pem file, e.g. to ~/Downloads/mykey.pem.
  4. Security group: allow SSH (port 22) from your IP only. We open 8080 later, also to your IP only.
  5. Launch, then copy the public IP. In this guide the example IP is 3.3.3.3 and the login user is ec2-user.

Optional: launch the EC2 using Claude (AWS CLI)

If you set up the AWS CLI, Claude can create the server too. It writes the command, you approve, it runs.

COPY THIS PROMPT

Using the AWS CLI that is already configured, launch one Amazon Linux 2023 t3.small EC2 in ap-south-1 with my key pair mykey and a security group that allows port 22 and 8080 from my current public IP only. Show me each command before you run it and wait for my yes.

Example command Claude runs (after your yes)
aws ec2 run-instances --image-id resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 \
  --instance-type t3.small --key-name mykey --security-group-ids sg-0123456789 \
  --count 1 --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=jenkins-demo}]'

The master prompt (copy-paste)

Open the Claude Code panel (or run claude) in VS Code and paste this. Change the IP and key path to yours.

MASTER PROMPT

You will set up a full Jenkins CI/CD server on my EC2 over SSH. Details:
• Key file: ~/Downloads/mykey.pem   • Server IP: 3.3.3.3   • Login user: ec2-user   • OS: Amazon Linux 2023.
Do these, and show me each command and wait for my approval before running it:
1) Fix key file permissions with chmod 400.
2) Install Java 17 and Jenkins from the official Jenkins repo.
3) Install Docker, start it, and add the jenkins user to the docker group.
4) Open port 8080 to my IP only (tell me the AWS CLI command, or how to do it in the console).
5) Read the initial admin password.
6) Skip the setup wizard using Configuration as Code (JCasC) and install plugins with jenkins-plugin-cli: git, workflow-aggregator, docker-workflow, credentials.
7) Create an admin user.
8) Create a Pipeline job that uses the Jenkinsfile in my repo: <your-git-url>.
Never print the contents of my .pem file. Use placeholders for any secret.

The real commands Claude runs (over SSH)

1 · protect the key, then connect
chmod 400 ~/Downloads/mykey.pem
ssh -i ~/Downloads/mykey.pem ec2-user@3.3.3.3
2 · Java 17 + Jenkins (official repo, Amazon Linux 2023)
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo dnf install -y java-17-amazon-corretto
sudo dnf install -y jenkins
sudo systemctl enable --now jenkins
3 · Docker + let Jenkins use it
sudo dnf install -y docker
sudo systemctl enable --now docker
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins   # so the new group takes effect
4 · open port 8080 to your IP only
aws ec2 authorize-security-group-ingress --group-id sg-0123456789 \
  --protocol tcp --port 8080 --cidr 203.0.113.5/32   # your IP/32
5 · read the first-time password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
6 · skip the wizard (JCasC) + install plugins
# install plugins without the web wizard
sudo jenkins-plugin-cli --plugins git workflow-aggregator docker-workflow credentials configuration-as-code
# tell Jenkins to skip the setup wizard and read a JCasC file
echo 'JAVA_OPTS="-Djenkins.install.runSetupWizard=false -Dcasc.jenkins.config=/var/lib/jenkins/casc.yaml"' | sudo tee /etc/sysconfig/jenkins.override
sudo systemctl restart jenkins
7 · create the admin user (JCasC casc.yaml)
jenkins:
  securityRealm:
    local:
      allowsSignup: false
      users:
        - id: "admin"
          password: "${ADMIN_PASS}"   # from an env var, not typed in chat
  authorizationStrategy:
    loggedInUsersCanDoAnything:
      allowAnonymousRead: false
8 · create the pipeline job from your repo
jobs:
  - script: >
      pipelineJob('my-app') {
        definition {
          cpsScm {
            scm { git('https://github.com/you/my-app.git') }
            scriptPath('Jenkinsfile')
          }
        }
      }
Open http://3.3.3.3:8080, log in as admin, open the my-app job, and click Build Now. The stages should turn green.

A sample Jenkinsfile (in your repo)

Jenkinsfile · declarative
pipeline {
  agent any
  stages {
    stage('Checkout') { steps { checkout scm } }
    stage('Build')    { steps { sh 'docker build -t my-app:latest .' } }
    stage('Test')     { steps { sh 'docker run --rm my-app:latest npm test' } }
    stage('Deploy')   { when { branch 'main' } steps { sh './deploy.sh' } }
  }
  post { success { echo 'Done.' } failure { echo 'Open the red stage log.' } }
}

Guardrails: keep full AI access safe

SAFETY · LAYERS

You are giving an AI a lot of power. Do not rely on polite words alone. Use layers. If one layer misses, the next one blocks. Build them in this order.

  1. Claude Code permission rules (hard block, enforced by the tool, not the model). Put a .claude/settings.json in your project. Rules are checked in the order deny → ask → allow, so a deny always wins. .claude/settings.json
    {
      "permissions": {
        "allow": ["Bash(ssh -i * ec2-user@*)", "Read(./Jenkinsfile)"],
        "ask":   ["Bash(aws *)", "Bash(sudo *)"],
        "deny":  ["Read(./*.pem)", "Read(~/.aws/credentials)",
                  "Bash(rm -rf *)", "Bash(mysql *)"]
      }
    }
    Note: a deny on Read(./*.pem) stops Claude from opening your key. Bash pattern matching is limited, so to truly stop dangerous SQL, block it at the database (step 3), not only here.
  2. A CLAUDE.md rule file (soft guide). Put plain rules Claude should follow, e.g. "Always ask before any sudo. Never read *.pem or .env. Never drop a database." Important: this is guidance that shapes what Claude tries to do — it is not a hard block. The real wall is the permission rules above.
  3. A dedicated Linux user for the AI with a small sudo allowlist. Do not let it be full root. /etc/sudoers.d/aiops
    # user 'aiops' may run ONLY these, nothing else
    aiops ALL=(root) NOPASSWD: /usr/bin/systemctl restart jenkins, \
      /usr/bin/dnf install -y *, /usr/bin/jenkins-plugin-cli *
  4. Protect the database with grants (the strongest SQL guard). Give the AI a user that cannot touch production, and an app user that can only insert and read. MySQL
    -- read-only helper with NO grants on prod_db at all
    CREATE USER 'ai_ro'@'%' IDENTIFIED BY '••••';
    -- (grant nothing on prod_db, so it simply cannot read or change it)
    
    -- app user: INSERT + SELECT only, no UPDATE/DELETE/DROP
    CREATE USER 'ai_app'@'%' IDENTIFIED BY '••••';
    GRANT INSERT, SELECT ON app.* TO 'ai_app'@'%';
    FLUSH PRIVILEGES;
    Because ai_app has no UPDATE, DELETE or DROP, even a wrong AI command cannot delete or drop data.
  5. AWS IAM least privilege with an explicit Deny on the scary actions and the protected resource. IAM policy
    {
      "Version": "2012-10-17",
      "Statement": [
        { "Sid": "AllowDailyWork", "Effect": "Allow",
          "Action": ["ec2:Describe*","ec2:RunInstances","s3:GetObject","s3:PutObject","rds:Describe*"],
          "Resource": "*" },
        { "Sid": "DenyDangerous", "Effect": "Deny",
          "Action": ["rds:DeleteDBInstance","s3:DeleteObject"],
          "Resource": ["arn:aws:rds:ap-south-1:123456789012:db:prod-db",
                       "arn:aws:s3:::prod-bucket/*"] }
      ]
    }
    In IAM an explicit Deny always beats an Allow, so the production DB and bucket are safe.
  6. Take a backup first. Before any AI run: an RDS snapshot, an EBS snapshot, and a git commit. If something goes wrong, you restore in minutes.
    aws rds create-db-snapshot --db-instance-identifier prod-db --db-snapshot-identifier pre-ai-$(date +%F)
    aws ec2 create-snapshot --volume-id vol-0123 --description "pre-ai"
COMPARISON CARDAI Coding

Soft instructions vs hard permissions

Soft (CLAUDE.md): you ask Claude to be careful. It usually listens, but it is advice, not a wall.
Hard (settings.json deny, OS user, DB grants, IAM Deny): the system blocks the action even if the AI tries.
Rule: use both, but trust only the hard layers for danger.
Ravindra Bagale · ravindrabagale.com/ai-coding

Safety checklist (quick)

  • Make Claude ask approval for each command (ask rules + "wait for my yes" in the prompt).
  • Never paste the .pem contents into the chat. Point to the file path only.
  • Open ports (22, 8080) to your IP only, not 0.0.0.0/0.
  • Delete the instance when you finish practice, so it is safe and free of cost.

Save tokens and money

SMART AI USE
  1. One master prompt, then short replies. After the first prompt, answer "yes" or "next" instead of re-explaining.
  2. Paste only the error lines when a step fails, not the whole log.
  3. Start a fresh chat for a new server so old text is not resent each time.
See more AI Coding guides for token-saving tips.

Quick quiz

1. What is the only manual step in this guide?

Launching one EC2 server. Claude does the rest over SSH.

2. Do rules in CLAUDE.md hard-block an action?

No. CLAUDE.md is guidance. The hard block is the permission rules in .claude/settings.json (and OS, DB and IAM limits).

3. In Claude Code, which wins: allow or deny?

Deny. Rules run deny → ask → allow, so a deny always wins.

4. How do you really stop the AI from dropping a database?

At the database: give it a user with no UPDATE/DELETE/DROP grants (and no grants at all on prod).

5. What should you never paste into the chat?

The contents of your .pem key. Share only the file path.

Save these cards

INTERVIEW CARDAI Coding

Can AI set up a server safely?

Answer: yes, if you add layers: tool permission rules, a limited OS user, database grants, and IAM Deny rules — plus approval for each command.
Key line: never trust soft instructions alone for dangerous actions.
Ravindra Bagale · ravindrabagale.com/ai-coding
REVISION CARDAI Coding

100% Jenkins by Claude in 3 ideas

1 Start: launch one EC2, give Claude the key path and IP.
2 Build: Claude installs Java, Jenkins, Docker, plugins over SSH.
3 Guard: deny rules, limited sudo user, DB grants, IAM Deny, backups.
Ravindra Bagale · ravindrabagale.com/ai-coding
Same "100% AI, no hurdles" series: see the companion guide Excel Dashboard 100% Done by AI.