A beginner-friendly comparison of Jenkins Freestyle jobs and Declarative Pipelines on AWS EC2, with examples and a clear recommendation."
tags: aws, jenkins, devops, cicd
When I started learning Jenkins on AWS, the first question I hit was: "Should I create a Freestyle job or a Pipeline?" Both can build and deploy your code, but they work very differently. In this article I explain both in simple terms, compare them, and help you decide which one to use on your EC2-hosted Jenkins server.
What is a Freestyle Job?
A Freestyle job is the classic, beginner-friendly way to create a build in Jenkins. You configure everything through the web UI by clicking and filling in forms:
- Choose a source code repository (GitHub)
- Add a build trigger (manual, webhook, or poll SCM)
- Add build steps (for example, "Execute shell")
- Add post-build actions (for example, notifications)
Example: Docker build in a Freestyle job (Execute shell step)
docker build -t myuser/cloudcart:latest . docker login -u $DOCKER_USER -p $DOCKER_PASS docker push myuser/cloudcart:latest docker run -d -p 8081:80 myuser/cloudcart:latest Pros
- Very easy to learn, with no coding needed
- Fast to set up for simple tasks
- Good for first labs and quick tests
Cons
- The configuration lives inside Jenkins, not in your Git repository
- Hard to copy, review, or version-control
- Complex flows (multiple stages, parallel steps) get messy
- If the Jenkins server is lost, the job setup is lost too
What is a Declarative Pipeline?
A Declarative Pipeline defines your whole CI/CD flow as code, in a file called a Jenkinsfile stored in your GitHub repo. It follows a clear, structured syntax made of stages and steps.
Example: Jenkinsfile
pipeline { agent any environment { IMAGE_NAME = "myuser/cloudcart" } stages { stage('Checkout') { steps { git branch: 'main', url: 'https://github.com/myuser/cloudcart.git' } } stage('Build Docker Image') { steps { sh 'docker build -t $IMAGE_NAME:latest .' } } stage('Push to Docker Hub') { steps { withCredentials([usernamePassword(credentialsId: 'dockerhub-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) { sh 'echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin' sh 'docker push $IMAGE_NAME:latest' } } } stage('Deploy') { steps { sh 'docker rm -f cloudcart || true' sh 'docker run -d --name cloudcart -p 8081:80 $IMAGE_NAME:latest' } } } post { success { echo 'Pipeline completed successfully!' } failure { echo 'Pipeline failed. Check the logs.' } } } Pros
- Pipeline as Code: it is versioned in Git with your application
- A visual Stage View shows exactly which stage passed or failed
- Easy to review, reuse, and roll back
- Supports parallel stages, conditions, and approvals
- Survives a Jenkins restart and can resume
Cons
- Slightly steeper learning curve (you need to learn the syntax)
- A small typo in the Jenkinsfile can break the build
Freestyle vs Declarative Pipeline: Side-by-Side
| Feature | Freestyle Job | Declarative Pipeline |
|---|---|---|
| Configuration | Web UI (clicks) | Code (Jenkinsfile) |
| Stored in Git | No | Yes |
| Learning curve | Very easy | Moderate |
| Multi-stage workflows | Difficult | Built in |
| Stage visualization | No | Yes (Stage View) |
| Parallel execution | Limited | Yes |
| Reusability | Low | High |
| Best for | Simple jobs, learning | Real CI/CD projects |
When Should You Use Which?
Use a Freestyle Job when:
- You are a beginner running your first Jenkins lab
- The task is small (one script, a quick test, a cleanup job)
- You just want to understand how Jenkins works
Use a Declarative Pipeline when:
- You are building a real CI/CD workflow (build → test → push → deploy)
- You want your pipeline stored in GitHub with your code
- You work in a team or want a production-style setup
- You plan to integrate tools like Docker, SonarQube, ECR, or Kubernetes
How to Create a Pipeline Job on Jenkins (EC2)
- Open Jenkins at
http://<EC2-Public-IP>:8080 - Click New Item, enter a name, and select Pipeline
- Under Pipeline, choose Pipeline script from SCM
- Select Git and paste your repository URL
- Set the branch (for example
main) and the Script Path asJenkinsfile - Click Save, then Build Now
- Open Stage View to watch each stage run
Tip: Make sure port 8080 is open in your EC2 Security Group, and store secrets such as Docker Hub credentials in Manage Jenkins → Credentials, never inside the Jenkinsfile.
My Recommendation
Start with a Freestyle job to understand the basics: how Jenkins pulls code, runs a shell command, and shows console output. Once you are comfortable, move to Declarative Pipelines. They are the industry standard for CI/CD, they are cleaner, and they make your project look far more professional on your GitHub and resume.
Conclusion
Freestyle jobs are great for learning, but Declarative Pipelines are what you will use in real projects. Treating your pipeline as code gives you version control, visibility, and repeatability, which are the core ideas of DevOps on AWS.
If you are learning Jenkins on EC2 too, try converting one of your Freestyle jobs into a Jenkinsfile today. It is the best way to learn.
Author: Vishal Patil
LinkedIn: vishalpatil-devops-aws
GitHub: VishalPatil-DevOps-AWS




