Run Unix Shell Commands

You can configure a job to run a Unix shell script or execute commands when a build runs:

  1. Open the job’s configuration page.

  2. Click the Steps tab.

  3. From Add Step, select Common Build Tools, then select Unix Shell.

  4. In Script, enter the shell script or commands.

    The script runs, using the workspace as the current directory. If the shell script doesn’t specify a header line, such as #!/bin/sh, the system shell will be used. You can also use the header line to write a script in another language, such as Perl (#!/bin/perl), or control the options that shell uses.

    You can also use Kubernetes, Docker, and OCIcli commands in the shell script. Make sure that you have the required software in the job’s build executor template before you run a build.

  5. To show the values of the variables and hide the input-output redirection in the build log, select the (-x) Expand variables in commands, don’t show I/O redirection option.

    To show the command as-it-is in the build log, select the (-v) Show commands exactly as written option.

  6. Click Save.

Tip:

Use Docker-In-Docker with Shell Scripts

In VB Studio, Docker-in-Docker functionality is implemented using a methodology known as “sibling” containers, which means that a build creates images and containers in the deployment VM’s Docker environment. Since multiple Docker executors share the same deployment VM, the images and containers will be shared among builds.

Note: If your organization’s builds use Docker executors and if those builds create Docker images and Docker containers, they’ll be managed by the Docker environment in the deployment VM. This allows builds to interact with images and containers from other builds. If your project contains sensitive data and requires its build to run isolated in a VM, you should set up the build using VM executors instead.

Using a simple command, such as docker rm $(docker container -q), in a shell script in a build could have the unintended consequence of killing containers that were created by other builds. To prevent this from happening, follow these recommendations to create and remove Docker images and containers: