Skip to main content

Why should I know if condition in bash especially for Devops?

Hi All!

Today we're going to see and learn if / elseif condition in bash.

Everybody have a thought why if condition is main important to learn than other statements in bash. Let's see why

It is always good to have knowledge on powershell, python and especially bash as a Devops guy. Nowadays most of the organization prefers Infrastucture as Code (Iac) with DRY (Donot Repeat Yourself) mostly. i.e. single/same YAML code file should be applicable for their multiple environments.

Consider an example that an organization has Dev, QA and Production environments. They need same infra to be deployed on all the environments after the verification from Dev then QA then finally Production.

So here, Infrastucture is not going to change, only the environment gets changed (i.e. subscription, resourcegroup, resourcename ...etc,). so we should have a single YAML file based on condition.

But, why learning Bash "if condition" especially is a question here when python, powershell sripting tech available? because

"If condition" applied on YAML is as similar as bash script. so that if we know bash script, it will be easy to work with YAML with some logical aspects.

Note: I'm not saying that bash is best than other. Powershell, Bash and python all are suits based on need.

Please look into the below image, I have a single YAML with if-elseif for 3 environments in Azure Devops.

Comments

Popular posts from this blog

Azure Public IP(s) are zone redundant free of cost natively - Generally Available Availability zone gives high availability to an application as well as information by forestalling the physical datacenter disappointments by involving replication of the asset in extra datacenter. Azure typically has 3 zones per region (and not all regions support zone). Thus, while setting up the environment we really want to pick the right region based on our usecase. Public IP helps to access a resource or an application publicly. Azure offers 2 types of SKU for public IP as below Basic Standard Only Standard SKU gives zone facility. Basic SKU is always non-zonal and this SKU also will be retired 09/2025. Standard public IP can be fell into any of the below category No Zone / Non-Zonal - No availability zone at all Zonal - Our services can be replicated in any one of selected zones from three zones. Zone redundant - Resource will be replicated in all 3 zones. It is opposite of...
create and read a file in Linux As a cloud and Devops engineers, we need to know to work with Linux is always helpful to handle some critical situations. There are multiple ways to create and read a file in Linux. In this article we're going to learn about touch command. Let's work with followings in this article pwd - To show present working directory touch - To create an empty file ls - To list the files from the current directory echo - To display message as well as write into a file. '>' - write into a file. '>>' - append it to a file cat - To read content of file we'll see writing and appending into a file in my upcoming post.
Avoid YAML Validation error in azure devops pipeline Hi All! Consider a scenario that you committed a YML CI/CD file on the repository with some syntax, indentation and/or other error(s). so that pipeline failed. After you find some errors and rectified in the repository file and committed again but pipeline still gets failed because some errors are still there. Now you afraid that even if you fixed error in all the places, what happens if pipeline failed again because your project lead or manager set up build notification mail trigger for build success and fails. you need to answer them for build fail reason. Azure devops pipelines offers YAML validation feature after altered and before committed and before run pipeline. To utilize this feature, what we do is, Instead of modifying the file from repository, Do as below Go to the specific build click "Edit Pipeline" Modify/fix errors and click "validate" as shown in the picture below ...