Case Statements in Linux are one of the efficient ways of selecting a condition in Linux.
Hi everyone, so I am very excited to share how to use case statement in Linux with Azure Devops. I have been working on C# for around 5 years and now working as a devops consultant in my current organization.
Most of my works are related to working on creating Azure Devops with Terraform and Ansible for infrastructure automation. One of the requirements that cam was to validate my variables against some of the values that has to be used while triggering the Azure Devops pipeline or we can say that by calling the azure devops api.
I am using a bash task with an inline script which we can use as given below:
case "$(os_type)" in "Red Hat") echo "Seleted value is $(os_type)." ;; "Windows Sever 2016") echo "Seleted value is $(os_type)." ;; "CentOS") echo "Seleted value is $(os_type)." ;; *) echo "Valid values for os_typeare "Red Hat", Windows Sever 2016 and CentOS." ;; esac
Here I am using a case statement to check the input value and compare it with the available values and echo the result.
Hope so that this will help you. Do let me know in the comments section if you need any help related to Azure Devops.
There have been times when I have copied some file from my computer with Windows on to a Linux server. Then I have found this issue very common. You can learn more about it here.
Today, while working I found a very strange error coming while trying to execute a Linux script. The error what I was getting said that script does not exits although, I was able to edit it using the vi editor.
After a long search found that the Linux was not able to read the file. as it was copied/ developed on a windows machine. So, there a very simple solution to this problem.
We have a package available i.e. dos2unix which can be installed on any flavor of Linux server and it can be used to convert the files into Linux readable files. Given below are the commands that we can use to install dos2unix
sudo yum install dos2unix -y
After we have installed dos2unix package we can execute a very simple command to convert the file so that unix system can easily interpret it or execute it.
Here file.sh is the file that needs to be converted to unix based file system.
There are two ways in which you can delete a local branch in Git. Both of the ways are described as below :
The first way to delete a local git branch is by using the -d git command. This command will only work when you have commited all your changes and pushed it to the server. The syntax for deleting the local branch is highlighted below.
git branch -d Branch_Name
Example : git branch -d feature1
Here feature1 is the local branch you want to delete.
There will be cases when you will want to delete your local branch for example when your local branch becomes corrupt. In this case when you have decided to delete the branch forcefully, then you can using the -D git command. The syntax below highlights how this can be acheived.
git branch -D Branch_Name
Git is a version control system that can be used for storing the source code at the centralized server or location, so that multiple members of the team can work on the application at the same time.
There will be scenarios where you will want to move the branch pointer to the different commit. So, we have two ways to resolve this.
Let’s say that you are working in your current branch which you have checked out from GIT. Then, we can make use of the git reset –hard command. Please find below a sample example of the git reset –hard command.
git reset --hard d17e40c50b442d84eca44210b4964770be229a19
Now, lets say that you are in a separate branch and you want your branch pointer to point to a commit in some other branch. If you want to achieve this, then you can make the use of the git branch command. Please find a sample below showing how we can acheive this:
git branch -f master d17e40c50b442d84eca44210b4964770be229a19
Here, we are pointing to the master branch which is having a commit id of d17e40c50b442d84eca44210b4964770be229a19.
How to undo changes in Git?
How to remove untracked files in Git?
How to change remote origin in Git?
Staging area in Git?
What does git prune remote origin do?
What is git checkout?
how to track revisions in Git?
How to delete local branch in Git?
Git is a very popular version control system. And its used by many developers whether they are developing any software or they are developing some AI code.
It’s very imprtant to understand how a version control system like GIT works and how we can commit and push our code to the remote repository. The main benefit of using any version control system is that it keeps different versiosn based on the commit.
In GIT we have we have a workspace where we keep our source code on which we want to work. We have local workspace and remote workspace when we are working with any version control software.
There are two branches available whenever you create a new GIT repository. The two branches are master and develop.
Now let’s see which command helps you track the revisions in git.
Git is a command line utility that is used to working with source version control. Git checkout command is used to switch to a use version or to create in a new branch. Git checkout is one of the most commony used commands that we use with branches.
There are two varieties in which Git checkout command can be used:
Git bash is the source code management system for the Windows operating system. If you want to install git bash then you can download it from here
When we want to work with any source code management repos like GitHub, Azure Repos, we can use git bash.
Given below are the steps that we can use to change the directory in git bash terminal:
Once you have completed your development and pushed all the changes to remote, you will want to delete the branch.
Sign up for our newsletter to receive the latest news and event postings.