Open In App

Introduction To Jenkins Pipeline As Code (Jenkinsfile)

Jenkins is an automating web server that build using java programming language. It come with support large number of plugins that made it as power CI/CD tool supporting to integration most of the softwares. In this article we will guide you through how to setup Jenkins Pipeline as Code from the scratch of setting up jenkins.

What Is A Jenkinsfile?

A Jenkinsfile is a text file that is written using Groovy syntax for defining Continuous Integration and Continuous Deployment (CI/CD) pipeline as Code. It supports versioning, reviewing and collaborating, automating the build, test and deployment process within Jenkins. It encapsulates the pipeline’s configuration for providing consistency and repeatability across software development projects.



Step By Step Implementation Of Jenkins Pipeline as Code

Step 1: Navigate To AWS Console

Step 2: Navigate To Running Instance



Step 3: Define Instance Configuration

Step 4: Configure Instance

Step 5: Launch Instance

Step 6: Connect To Instance

Step 7: Connect To EC2 Console

Step 8: Installation Of Jenkins

sudo yum install java* -y


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 yum upgrade
# Add required dependencies for the jenkins package
sudo yum install jenkins
sudo systemctl daemon-reload


Step 9: Verification of Java Applications

java --version
jenkins --version


Step 10: Starting Jenkins Server

systemctl enable jenkins --now


Step 11: Asking Jenkins Credentials

http://[IP_address]:8080


Step 12: Copying The Jenkins Password

sudo cat /var/lib/jenkins/secrets/initalAdminPassword


Step 13: Installing Suggested Plugins

Step 14: Installation Of Suggested Plugins

Step 15: Default User Access

Step 16: Instance Configuration

Step 17: Create A Jenkins Job

Step 18: Configuring The Jenkins Job

Step 19: Configure The jenkins Job With Jenkinsfile

pipeline {
agent any
stages {
stage('Build') {
steps {
echo "Build Stage"
}
}
stage('Test') {
steps {
echo "Test Stage"
}
}
// Additional stages
}
post {
always {
echo "This is Jenkinsfile"
}
}
}


Step 20: Build Jenkins Job

Jenkinsfile – FAQ’s

What Is Jenkinsfile Used For?

It used for defining Jenkins pipeline such as build, test, git stages etc..

What Is the Difference between jenkins pipeline and jenkinsfile?

In Jenkinsfile is a file that defines all steps in a single jenkins file whereas Jenkins pipeline is a plugin that suits for creating and managing delivery pipelines in jenkins.

What is the syntax of Jenkinsfile?

Jenkinsfile can be written on using two syntaxs one is delcartice and other is scripted pipeline as code.

What is the programming language for Jenkinsfile?

Many set of programming languages are used in Jenkins including Java, Javascript, Groovy, Golang etc.. It is not limited to some programming languages only.


Article Tags :