Using Steampipe in a GitLab CI/CD Pipeline
GitLab provides a hosted environment in which you can build, test, and deploy software. This happens in a GitLab Runner. Let's install Steampipe into a shared runner on gitlab.com, then install a plugin and run a query.
Installing Steampipe in a GitLab Runner
To run scripts when you push changes to a gitlab.com repo, you place them in a file called .gitlab-ci.yml
. Here's an example that installs Steampipe into the runner's environment.
install:stage: buildscript:- echo "Hello, $GITLAB_USER_LOGIN, let's install Steampipe!"- /bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/turbot/steampipe/main/install.sh)"
The official command to install Steampipe begins with sudo
. That isn't necessary here, though, because in this environment you already are the root user.
Running Steampipe in a GitLab Runner
Steampipe cannot, however, run as root. So we'll create a non-privileged user, and switch to that user in order to run Steampipe commands. Our first command will install the Hacker News plugin.
install:stage: buildscript:- echo "Hello, $GITLAB_USER_LOGIN, let's install Steampipe!"- adduser --disabled-password --shell /bin/bash jon- /bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/turbot/steampipe/main/install.sh)"- su jon -c "steampipe plugin install hackernews"
Next, we'll add a file called hn.sql
file to the repo.
selectid,titlefromhackernews_itemwheretype = 'story'and title is not nullorder byid desclimit 5
Finally, we'll copy hn.sql
into the home directory of the non-privileged user, then run a query.
install:stage: buildscript:- echo "Hello, $GITLAB_USER_LOGIN, let's install Steampipe!"- adduser --disabled-password --shell /bin/bash jon- cp hn.sql /home/jon- cd /home/jon- ls -l- /bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/turbot/steampipe/main/install.sh)"- su jon -c "steampipe plugin install hackernews"- su jon -c "steampipe query hn.sql"
That's it! Now you can use any of Steampipe's plugins to enrich your GitLab pipelines.