KEMBAR78
Advanced Jenkins Assignments With Solutions | PDF | Version Control | Computing
0% found this document useful (0 votes)
16 views9 pages

Advanced Jenkins Assignments With Solutions

The document outlines 20 advanced Jenkins assignments aimed at enhancing CI/CD processes, covering topics such as Docker layer caching, Terraform integration, artifact versioning, and secure secrets management. Each assignment includes specific goals, steps to implement, and the benefits of the approach. The assignments also address automation, compliance, and real-time testing to improve overall efficiency and security in software delivery.

Uploaded by

vinay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views9 pages

Advanced Jenkins Assignments With Solutions

The document outlines 20 advanced Jenkins assignments aimed at enhancing CI/CD processes, covering topics such as Docker layer caching, Terraform integration, artifact versioning, and secure secrets management. Each assignment includes specific goals, steps to implement, and the benefits of the approach. The assignments also address automation, compliance, and real-time testing to improve overall efficiency and security in software delivery.

Uploaded by

vinay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Advanced Jenkins Assignments with Solutions

Assignment 1: Docker Layer Caching in Jenkins

Goal: Speed up Docker builds by caching layers.

Steps:

1. Use `docker` inside Jenkins agent with mounted cache.

2. Configure Jenkinsfile to use cache-from:

```groovy

docker.build("myapp:${BUILD_NUMBER}", "--cache-from=myapp:latest .")

```

3. Archive `.docker` directory if needed.

Benefit: Faster builds, reduced compute time.

Assignment 2: Infrastructure as Code CI/CD (Terraform Integration)

Goal: CI/CD pipeline for Terraform infrastructure.

Steps:

1. Jenkinsfile stages:

- `terraform fmt`

- `terraform validate`

- `terraform plan`

- `terraform apply` (manual approval)

2. Store state in remote backend (S3).

3. Use `withCredentials` for AWS access.

Benefit: Infrastructure-as-Code with controlled releases.

Page 1
Advanced Jenkins Assignments with Solutions

Assignment 3: Artifact Versioning & Promotion Pipeline

Goal: Promote builds from dev staging prod.

Steps:

1. Build in dev, store artifact (.jar/.war).

2. Create manual approval stage.

3. Promote build by reusing stored artifact.

Benefit: Same artifact reused, avoids re-building.

Assignment 4: Dynamic Job Creation Using Job DSL

Goal: Auto-create jobs using DSL.

Steps:

1. Create DSL script like:

```groovy

job('my-generated-job') {

scm { git('https://github.com/myrepo') }

triggers { scm('* * * * *') }

```

2. Run via Seed Job.

Benefit: Dynamic job management.

Assignment 5: Audit and Compliance Pipeline

Page 2
Advanced Jenkins Assignments with Solutions

Goal: Track audit logs of builds & artifacts.

Steps:

1. Enable Jenkins Audit Trail plugin.

2. Send logs to ELK or Splunk.

3. Add Jenkinsfile step to archive signed artifact checksum.

Benefit: Compliance-ready delivery.

Assignment 6: Secure Secrets Management with Vault

Goal: Use HashiCorp Vault to store secrets.

Steps:

1. Setup Vault plugin.

2. Create secrets like `db_password`.

3. Use withCredentials in Jenkinsfile:

```groovy

withCredentials([string(credentialsId: 'vault-db-password', variable: 'DB_PASS')]) {

sh "echo $DB_PASS"

```

Benefit: Secure secret injection.

Assignment 7: Chaos Testing Job (Real-Time Issue Simulation)

Goal: Test how app reacts to failure.

Steps:

Page 3
Advanced Jenkins Assignments with Solutions

1. Add chaos test stage using tools like `chaos-mesh` or simple script to kill pod.

2. Analyze behavior.

Benefit: Ensure system resiliency.

Assignment 8: Auto-Scaling Jenkins Agents on Kubernetes

Goal: Auto-scale Jenkins agents on Kubernetes.

Steps:

1. Use Kubernetes Plugin.

2. Define pod templates in Jenkins.

3. Agents spin up only when needed.

Benefit: Save cost and improve efficiency.

Assignment 9: Build Metrics Dashboard with Grafana

Goal: Show build stats on dashboard.

Steps:

1. Export metrics via Prometheus plugin.

2. Visualize in Grafana.

Benefit: Real-time observability.

Assignment 10: Nested & Parallel Stages with Retry Logic

Goal: Use retry and parallel logic.

Jenkinsfile:

Page 4
Advanced Jenkins Assignments with Solutions

```groovy

parallel(

backend: {

retry(3) { sh 'mvn test' }

},

frontend: {

retry(2) { sh 'npm run test' }

```

Benefit: Smart error handling and speed.

Assignment 11: Jenkins + SonarQube Integration for Code Quality

Goal: Integrate SonarQube in pipeline.

Steps:

1. Setup SonarQube scanner.

2. Jenkinsfile:

```groovy

withSonarQubeEnv('SonarQube') {

sh 'sonar-scanner'

```

Benefit: Code quality gates.

Page 5
Advanced Jenkins Assignments with Solutions

Assignment 12: Conditional Deployments Based on Git Commit Messages

Goal: Control deploy via commit message.

Steps:

1. Jenkinsfile:

```groovy

def msg = sh(script: 'git log -1 --pretty=%B', returnStdout: true).trim()

if (msg.contains('#skip-deploy')) {

echo 'Skipping deploy'

} else {

// deploy

```

Benefit: Flexible deploy logic.

Assignment 13: Trigger Downstream Jobs with Artifacts

Goal: Use artifact between jobs.

Steps:

- Job 1: Archive `.war` file.

- Job 2: Use `copyArtifacts` plugin to fetch it.

Benefit: Clean separation of stages.

Assignment 14: Jenkins + Helm Chart Deployment to K8s

Page 6
Advanced Jenkins Assignments with Solutions

Goal: Use Helm instead of kubectl.

Jenkinsfile:

```groovy

sh 'helm upgrade --install app ./chart --set image.tag=${BUILD_NUMBER}'

```

Benefit: Versioned, declarative deploys.

Assignment 15: Rollback on Deployment Failure (With Version Tracking)

Goal: Rollback failed deploy.

Steps:

1. Store current version in S3 or file.

2. On failure, rollback to previous tag.

Benefit: Stability in production.

Assignment 16: Jenkins File Parameter Injection from External JSON

Goal: Inject config from JSON.

Steps:

```groovy

def config = readJSON file: 'build-config.json'

env.BRANCH = config.branch

```

Benefit: Config-driven pipelines.

Page 7
Advanced Jenkins Assignments with Solutions

Assignment 17: Jenkins Pipeline with Git Tagging Logic

Goal: Tag after build.

Steps:

```groovy

sh 'git tag v1.0-${BUILD_NUMBER}'

sh 'git push origin v1.0-${BUILD_NUMBER}'

```

Benefit: Version tracking.

Assignment 18: Jenkins Webhook Proxy with NGROK or LocalTunnel

Goal: Simulate webhook locally.

Steps:

1. Run: `ngrok http 8080`

2. Use URL in GitHub webhook.

Benefit: Test locally.

Assignment 19: Secret Rotation Automation Pipeline

Goal: Rotate secrets automatically.

Steps:

1. Generate new password.

2. Update Vault/AWS Secrets.

3. Notify & restart app.

Page 8
Advanced Jenkins Assignments with Solutions

Benefit: Strong security practice.

Assignment 20: Jenkins Groovy Script Console Automation

Goal: Admin automation with Groovy.

Script:

```groovy

Jenkins.instance.getAllItems().each {

println it.name + ' - ' + it.getLastBuild()?.getResult()

```

Benefit: Admin automation.

Page 9

You might also like