Most simple CI pipeline
When we think about CI pipelines we often have tools like Jenkins, Gitlab or Travis CI in mind. This article will show how we can set up a simple CI pipeline in a shell.
Actually pipelines are an integral part of every UNIX shell. We can use our shell to build a simple pipeline that gets us a result within seconds.
Let’s say we want to build a pipeline for Terraform. Once we have created our code we should do a syntax check with
The next step is to run
terraform apply with
-auto-approve but we want to do that only if our syntax check succeeded.
terraform validate && terraform apply -auto-approve
We can run that pipeline manually each time after we changed something in our .tf files. But lets go one step further and trigger the pipeline automatically every time we save one of our .tf files. We use entr for that task.
Entr reads a list of files from stdin and runs the given command when one of those files changes.
ls *\.tf | entr /bin/bash -c "terraform validate && terraform apply -auto-approve"
Of course that is not a replacement for a full featured CI tool but it is a first step that can run on our local machine before we push changes to a remote repository. Why should we do those tasks manually if we can automate them within minutes?