0
0
Jenkinsdevops~5 mins

Why Jenkins for automation - Why It Works

Choose your learning style9 modes available
Introduction
Automation helps save time and avoid mistakes by running tasks automatically. Jenkins is a tool that makes it easy to automate software building, testing, and deployment without manual work.
When you want to automatically test your code every time you save changes.
When you need to build your software and create packages without doing it by hand.
When you want to deploy your app to a server automatically after tests pass.
When you want to run repetitive tasks like backups or reports on a schedule.
When you want to see the results of your automation in one place with clear reports.
Commands
This command starts the Jenkins server so you can access its web interface and set up automation jobs.
Terminal
java -jar jenkins.war
Expected OutputExpected
Running from: /home/user/jenkins.war 2024-06-01 12:00:00.000+0000 [id=1] INFO org.eclipse.jetty.server.Server#main: Started @12345ms Jenkins is fully up and running
This command triggers a Jenkins job named 'my-job' to start a build automatically from the command line.
Terminal
curl -X POST http://localhost:8080/job/my-job/build --user admin:admin123
Expected OutputExpected
Started build #1 for job my-job
-X POST - Specifies that this is a POST request to trigger the build
--user admin:admin123 - Provides authentication to Jenkins
This command checks the status and details of the last build of 'my-job' in JSON format.
Terminal
curl http://localhost:8080/job/my-job/lastBuild/api/json --user admin:admin123
Expected OutputExpected
{"result":"SUCCESS","building":false,"number":1}
--user admin:admin123 - Provides authentication to Jenkins
Key Concept

If you remember nothing else from Jenkins automation, remember: it runs your tasks automatically so you don’t have to do repetitive work by hand.

Common Mistakes
Trying to start Jenkins without Java installed.
Jenkins runs on Java, so it needs Java to be installed first or it will fail to start.
Install Java (OpenJDK 11 or newer) before running Jenkins.
Triggering a Jenkins job without proper authentication.
Jenkins requires user credentials to allow job triggers, otherwise it denies access.
Use valid username and API token or password when triggering jobs via API.
Not checking build status after triggering a job.
You won’t know if your automation succeeded or failed without checking the build result.
Use Jenkins API or web interface to verify build status after triggering.
Summary
Start Jenkins server to access automation features.
Trigger jobs automatically using Jenkins API with authentication.
Check build results to confirm automation success.