Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4

TechWorld with Nana · Beginner ·☁️ DevOps & Cloud ·6y ago

Key Takeaways

Explains Jenkinsfile pipeline syntax and usage

Full Transcript

let's go ahead and create a Jenkins file in dev branch and I'm gonna do that using the get UI so let's go to dev and I'm gonna create a new file and this is the most basic Jenkins file that basically does nothing but this is the basic syntax we're going to go through a Jenkins file syntax in more detail in a later section but here I'm gonna explain you the required attributes for Jenkins file so the first thing is that Jenkins file can be written as a scripted pipeline or a declarative pipeline so the scripted pipeline was the first syntax of Jenkins file so what it is is basically it allows to write the whole configuration of the Jenkins file using groovy script so the only structure that you have there is this here and inside of this is basically groovy scripts and you can write the whole configuration here in a flexible manner as you wish so there is no predefined structure there however for people who didn't know or doesn't know groovy syntax or who hasn't worked with groovy is little bit difficult to start with that's why as a recent addition they actually edit declarative pipeline syntax from Jenkins file which is easier to get started with it has of course it's not as powerful as the scripted pipeline because here you're not limited in any way but it's easier to get started with because you have a predefined structure so this what you see here is basically pre given structure that you have to follow but again you don't have to think about how to script all this so you just fill in the gaps so what we saw here the note definition is basically same as these two lines here so in a declarative pipeline you declare that you are writing a pipeline and agent any basically means that this build is gonna run on any available Jenkins agent and agent can be a note it could be executors on that note whatever and this is more relevant when you have a Jenkins cluster so to say with master and slaves where you have Windows nodes and Linux nodes etc but here for the beginning for base we just say agent any so we'll just run with the next available agent and as I said these two are equivalent to this one here and they are required attributes you always have to use them the next required attribute is stages and this is where the whole work actually happens so you have different stages of that pipeline and inside the stages you define stage name and you can define as many stages as you want usually you have something like this so you have a build stage let's get rid of this one actually have a build stage maybe you have a test stage and then you have a deploy stage like this you can have additional ones like for example you might have a check out stage stage here and I don't know cleanup stage afterwards whatever and as you see inside the stage you have the steps and here goes the script that actually executes some comment on the Jenkins server or Jenkins agent so for example if you're building a JavaScript application all the NPM install NPM build etc scripts will go here like this if you are you know running tests or for Java back-end all the text execution scripts will be here and the deployment script will be here so right now let's just write simple echo comments to kind of test this so here we're gonna say building the application and here we're gonna say testing the application in here we are deploying the application and this is a very Jenkins file and this should work already so let's actually now we committed it and let's go back to our pipeline and let's scan it again and see the locks and it's doing something so as you see here it found Jenkins file in dev and now it's actually executing the Jenkins file right here so if I go back to my pipeline view I already see the first branch was built and that's a dev branch let's go inside and see the first execution so what happened here the first step that you see is check out the code the second one was built test deploy and here you can see the logs and this is what we echoed in each stage testing the application etc so now the question is where did this come from so this stage is something we didn't define before and it basically checks out the code so how does this happen this actually comes from let's go back to my pipeline and configure this actually comes from this one right here so by defining or by configuring that we want git repository with this URL to be checked out we basically in UI declaring that we want that checkout stage to happen right so it automatically adds to the pipeline stage now you could do that in your Jenkins file instead of configuring it in the pipeline configuration but I actually prefer to have that step configured in the pipeline you eye configuration so this is the result of Jenkins file execution and here inside of that branch configuration you also have some options like where you can build the branch manually and see the configuration but at this point it's important to note that most of the configuration will be done in Jenkins file or on the pipeline level in the configure mask so right here and not on the individual branch level so you wouldn't be doing anything here that's why you can only see the configuration but not edit the configuration so now what if you want to test some stuff or some changes in a Jenkins file let's say add one of the steps you want to test some groovy expression and you are new to groovy so you're just learning and you just want to try this out and it will be more effort to you know adjust the Jenkins filed and commit it and you know it has to check out again the changes and rebuild it again etc so there is actually a handy way to do that in Jenkins so we can test and execute the Jenkins file changes without having to commit each change so the way to do that is go to one of the branches so let's say in the dev and here you have the history of the build and if you click inside one of those builds and here you have a bunch of options and one of them is replay and what replay does is basically allows you to adjust the last run jenkins file and rerun it again so here let's say i want to try some groovy expression so the thing is in this inside the steps you can only write the command line comments so if you want to try it or if you want to execute groovy script then you have to enclose it inside script so script will be one of the steps so here you can have echo I delete it again so building the application and inside script we can write some groovy expression so let's say let's just write something whatever so if this is true then we're gonna say cool if not no not cool and then I'm gonna echo this and let's run okay so it's building now and here if I open this I see filling the application and the new message so when now we tested the changes in the Jenkins file without having to actually commit it to the repository another thing that you can do with the specific build is also so if you click on this triangle you actually see all this commands as well replace there but you can also do restart from stage so if you click here you see a list a drop down list of all the stages that you have defined so if one of the stages fails or I don't know you need to repeat this stage again you can actually choose one of the stages without having to repeat all the other so let's actually choose the deploy and if I run in again you see you will skip the previous stages and just do the last one which also could be pretty handy sometimes

Original Description

Jenkinsfile Pipeline Tutorial. Learn about Jenkinsfile, the pipeline as code. In this video I show the syntax of a Jenkinsfile, explain the differences between scripted and declarative syntax. I also show how to test something out in a Jenkinsfile by replaying it and how to skip stages via restart option. ▬▬▬▬▬▬ Topics covered * Pipeline Syntax: Scripted vs. Declarative * Basic Syntax * Test something in Jenkinsfile - Replay Jenkinsfile * Restart from stage This is the 3rd part of a complete jenkins tutorial for beginners: 1) Run Jenkins in a Docker Container 2) Create Multibranch Pipeline with Git 3) Basic Jenkinsfile Syntax 4) Git Integration - Trigger Jenkins build automatically ⭐️Full Playlist: https://www.youtube.com/playlist?list=PLy7NrYWoggjw_LIiDK1LXdNN82uYuuuiC For any questions/issues/feedback, please leave me a comment and I will get back to you as soon as possible. #devops #jenkins #docker #techworldwithnana #devopstools ------------------------------------------------------------------------------------------------------- Complete Docker and Kubernetes tutorial ► https://bit.ly/2YGeRp9 What is Kubernetes? ► https://youtu.be/VnvRFRk_51k Docker 🐳 vs Kubernetes ► https://youtu.be/9_s3h_GVzZc Complete Jenkins Pipeline Tutorial ► https://youtu.be/7KCS70sCoK0 -------------------------------------------------------------------------------------------------------- ✅ Connect with me Youtube ► https://www.youtube.com/channel/UCdngmbVKX1Tgre699-XLlUA DEV ► https://dev.to/techworld_with_nana Instagram ► https://www.instagram.com/techworld_with_nana/ Twitter ► https://twitter.com/Njuchi_/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from TechWorld with Nana · TechWorld with Nana · 26 of 60

1 What is Docker? Docker container concept explained || Docker Tutorial 1
What is Docker? Docker container concept explained || Docker Tutorial 1
TechWorld with Nana
2 What is a Docker Container? Docker Demo || Docker Tutorial 2
What is a Docker Container? Docker Demo || Docker Tutorial 2
TechWorld with Nana
3 How to install docker? Step by Step || Docker Tutorial 3
How to install docker? Step by Step || Docker Tutorial 3
TechWorld with Nana
4 8 Basic Docker Commands || Docker Tutorial 4
8 Basic Docker Commands || Docker Tutorial 4
TechWorld with Nana
5 Debugging Docker Containers with docker exec and docker logs || Docker Tutorial 5
Debugging Docker Containers with docker exec and docker logs || Docker Tutorial 5
TechWorld with Nana
6 Docker vs Virtual Machine | simply explained || Docker Tutorial 6
Docker vs Virtual Machine | simply explained || Docker Tutorial 6
TechWorld with Nana
7 Overview of Workflow with Docker - Docker in Practice || Docker Tutorial 7
Overview of Workflow with Docker - Docker in Practice || Docker Tutorial 7
TechWorld with Nana
8 Developing with Docker - Docker in Practice || Docker Tutorial 8
Developing with Docker - Docker in Practice || Docker Tutorial 8
TechWorld with Nana
9 Docker Compose Tutorial - Docker in Practice || Docker Tutorial 9
Docker Compose Tutorial - Docker in Practice || Docker Tutorial 9
TechWorld with Nana
10 Dockerfile Tutorial - Docker in Practice || Docker Tutorial 10
Dockerfile Tutorial - Docker in Practice || Docker Tutorial 10
TechWorld with Nana
11 Private Repository explained | Registry on AWS - Docker in Practice || Docker Tutorial 11
Private Repository explained | Registry on AWS - Docker in Practice || Docker Tutorial 11
TechWorld with Nana
12 Docker Volumes explained in 6 minutes
Docker Volumes explained in 6 minutes
TechWorld with Nana
13 Deploying the containerized application with Docker Compose || Docker Tutorial 12
Deploying the containerized application with Docker Compose || Docker Tutorial 12
TechWorld with Nana
14 Docker Volumes Demo || Docker Tutorial 13
Docker Volumes Demo || Docker Tutorial 13
TechWorld with Nana
15 Docker vs Kubernetes vs Docker Swarm | Comparison in 5 mins
Docker vs Kubernetes vs Docker Swarm | Comparison in 5 mins
TechWorld with Nana
16 What is Kubernetes | Kubernetes explained in 15 mins
What is Kubernetes | Kubernetes explained in 15 mins
TechWorld with Nana
17 Kubernetes Components explained! Pods, Services, Secrets, ConfigMap | Kubernetes Tutorial 14
Kubernetes Components explained! Pods, Services, Secrets, ConfigMap | Kubernetes Tutorial 14
TechWorld with Nana
18 Kubernetes Architecture explained | Kubernetes Tutorial 15
Kubernetes Architecture explained | Kubernetes Tutorial 15
TechWorld with Nana
19 Benefits of Kubernetes | Scalability, High Availability, Disaster Recovery | Kubernetes Tutorial 16
Benefits of Kubernetes | Scalability, High Availability, Disaster Recovery | Kubernetes Tutorial 16
TechWorld with Nana
20 Minikube and Kubectl explained | Setup for Beginners | Kubernetes Tutorial 17
Minikube and Kubectl explained | Setup for Beginners | Kubernetes Tutorial 17
TechWorld with Nana
21 Top 3 programming languages to learn in 2020 | meta analysis
Top 3 programming languages to learn in 2020 | meta analysis
TechWorld with Nana
22 Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18
Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18
TechWorld with Nana
23 Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
TechWorld with Nana
24 Run Jenkins in Docker Container - Jenkins Pipeline Tutorial for Beginners 1/4
Run Jenkins in Docker Container - Jenkins Pipeline Tutorial for Beginners 1/4
TechWorld with Nana
25 Create Multibranch Pipeline with Git - Jenkins Pipeline Tutorial for Beginners 2/4
Create Multibranch Pipeline with Git - Jenkins Pipeline Tutorial for Beginners 2/4
TechWorld with Nana
Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
TechWorld with Nana
27 Trigger Jenkins Build automatically - Jenkins Pipeline Tutorial for Beginners 4/4
Trigger Jenkins Build automatically - Jenkins Pipeline Tutorial for Beginners 4/4
TechWorld with Nana
28 Complete Application Deployment using Kubernetes Components | Kubernetes Tutorial 20
Complete Application Deployment using Kubernetes Components | Kubernetes Tutorial 20
TechWorld with Nana
29 Kubernetes Namespaces Explained in 15 mins | Kubernetes Tutorial 21
Kubernetes Namespaces Explained in 15 mins | Kubernetes Tutorial 21
TechWorld with Nana
30 Configure Build Tools in Jenkins and Jenkinsfile | Jenkins Tutorial
Configure Build Tools in Jenkins and Jenkinsfile | Jenkins Tutorial
TechWorld with Nana
31 Complete Jenkins Pipeline Tutorial | Jenkinsfile explained
Complete Jenkins Pipeline Tutorial | Jenkinsfile explained
TechWorld with Nana
32 Kubernetes Ingress Tutorial for Beginners | simply explained  | Kubernetes Tutorial 22
Kubernetes Ingress Tutorial for Beginners | simply explained | Kubernetes Tutorial 22
TechWorld with Nana
33 What is Helm in Kubernetes? Helm and Helm Charts explained  | Kubernetes Tutorial 23
What is Helm in Kubernetes? Helm and Helm Charts explained | Kubernetes Tutorial 23
TechWorld with Nana
34 How Websites Work | simply explained with examples
How Websites Work | simply explained with examples
TechWorld with Nana
35 What is JavaScript? | JavaScript Tutorial #1
What is JavaScript? | JavaScript Tutorial #1
TechWorld with Nana
36 What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
TechWorld with Nana
37 JavaScript Variables & JavaScript Data Types explained | JavaScript Tutorial #2
JavaScript Variables & JavaScript Data Types explained | JavaScript Tutorial #2
TechWorld with Nana
38 How Prometheus Monitoring works | Prometheus Architecture explained
How Prometheus Monitoring works | Prometheus Architecture explained
TechWorld with Nana
39 Where to write JavaScript | Where to execute JavaScript Code | JavaScript Tutorial #3
Where to write JavaScript | Where to execute JavaScript Code | JavaScript Tutorial #3
TechWorld with Nana
40 JavaScript Operators & JavaScript Conditionals | JavaScript Tutorial #4
JavaScript Operators & JavaScript Conditionals | JavaScript Tutorial #4
TechWorld with Nana
41 Pods and Containers - Kubernetes Networking | Container Communication inside the Pod
Pods and Containers - Kubernetes Networking | Container Communication inside the Pod
TechWorld with Nana
42 Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class
Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class
TechWorld with Nana
43 Kubernetes ConfigMap and Secret as Kubernetes Volumes | Demo
Kubernetes ConfigMap and Secret as Kubernetes Volumes | Demo
TechWorld with Nana
44 Pull Image from Private Docker Registry in Kubernetes cluster | Demo
Pull Image from Private Docker Registry in Kubernetes cluster | Demo
TechWorld with Nana
45 Kubernetes StatefulSet simply explained | Deployment vs StatefulSet
Kubernetes StatefulSet simply explained | Deployment vs StatefulSet
TechWorld with Nana
46 Yaml Tutorial | Learn YAML in 18 mins
Yaml Tutorial | Learn YAML in 18 mins
TechWorld with Nana
47 Terraform explained in 15 mins | Terraform Tutorial for Beginners
Terraform explained in 15 mins | Terraform Tutorial for Beginners
TechWorld with Nana
48 Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator | Part 1
Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator | Part 1
TechWorld with Nana
49 Managed Kubernetes Cluster explained | Kubernetes on Cloud (1/2)
Managed Kubernetes Cluster explained | Kubernetes on Cloud (1/2)
TechWorld with Nana
50 Step by Step Application Deployment on LKE using Helm | Kubernetes on Cloud (2/2)
Step by Step Application Deployment on LKE using Helm | Kubernetes on Cloud (2/2)
TechWorld with Nana
51 Kubernetes Operator simply explained in 10 mins
Kubernetes Operator simply explained in 10 mins
TechWorld with Nana
52 What is Infrastructure as Code? Difference of Infrastructure as Code Tools
What is Infrastructure as Code? Difference of Infrastructure as Code Tools
TechWorld with Nana
53 AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way
AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way
TechWorld with Nana
54 Prometheus Monitoring - Steps to monitor third-party apps using Prometheus Exporter | Part 2
Prometheus Monitoring - Steps to monitor third-party apps using Prometheus Exporter | Part 2
TechWorld with Nana
55 GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
TechWorld with Nana
56 Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
TechWorld with Nana
57 Kubernetes Services explained | ClusterIP vs NodePort vs LoadBalancer vs Headless Service
Kubernetes Services explained | ClusterIP vs NodePort vs LoadBalancer vs Headless Service
TechWorld with Nana
58 Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]
Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]
TechWorld with Nana
59 Containers on AWS Overview: ECS | EKS | Fargate | ECR
Containers on AWS Overview: ECS | EKS | Fargate | ECR
TechWorld with Nana
60 Kubernetes is dropping Docker support - What does it mean for YOU?
Kubernetes is dropping Docker support - What does it mean for YOU?
TechWorld with Nana

Related Reads

📰
Your monitoring cannot tell broken from off. Mine could not either.
Improve monitoring systems to distinguish between broken and intentionally offline components, a crucial aspect of system health checks
Dev.to AI
📰
AWS Self-Healing Infrastructure: Catching and Fixing Server Crashes with AI Autopilot
Learn how to use AWS Self-Healing Infrastructure with AI Autopilot to catch and fix server crashes automatically
Medium · DevOps
📰
Understanding a Real AWS CodePipeline CI/CD Flow: Source Build Deploy"
Learn how to set up a CI/CD pipeline using AWS CodePipeline, covering source, build, and deploy stages
Dev.to · Guna SantoshDeep Srivastava
📰
How to Use Terraform with Python for Infrastructure
Learn to manage infrastructure with Terraform and Python for efficient and automated deployment
Dev.to · qing
Up next
AWS, Azure, GCP: The One Thing Every Business Gets Wrong
AI Daily
Watch →